Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:06:56+00:00 2026-05-26T21:06:56+00:00

Look at this sample code: <a class=change href=# id=swap01><img src=off.gif></a></div> <a class=change href=# id=swap02><img

  • 0

Look at this sample code:

<a class="change" href="#" id="swap01"><img src="off.gif"></a></div>
<a class="change" href="#" id="swap02"><img src="off.gif"></a></div>
<a class="change" href="#" id="swap03"><img src="off.gif"></a></div>

<form>
<input type="hidden" name="field01" value="0" />
<input type="hidden" name="field02" value="0" />
<input type="hidden" name="field03" value="0" />
</form>

What I want to happen is that, for example, if I click on the image link within swap02:

1) The image source for that link changes from off.gif to on.gif
2) The corresponding hidden field in the form (field02) changes from 0 to 1.

When I click the same link again, it reverts back to off.gif and 0.

Just three are given as an example, but this needs to be scalable (up to 99 items).

Thanks a lot. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:06:57+00:00Added an answer on May 26, 2026 at 9:06 pm

    Try –

    $("a[id^='swap']").click(function(e) {
        e.preventDefault();
        var $img = $("img",this);
        $img.attr("src") == 'off.gif' ? $img.attr("src","on.gif") : $img.attr("src","off.gif");
        var $hf = $("input[name='field" + this.id.replace('swap','') + "']");
        $hf.val() == '1' ? $hf.val('0') : $hf.val('1');
    })
    

    Demo – http://jsfiddle.net/dwE78/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at this situation: www.websitea.com displays an img tag with a src attribute of
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
look at this code, <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script> function change() {
I am learning the boost::lambda library and for that I wrote this sample code
I have wired experience with reflections. At first some sample code: public abstract class
Please look at simple code below public class A{} public class B: A{} public
Have a look a this simple example. I don't quite understand why o1 prints
difficult to look this up if it has been asked previously since I don't
Not exactly sure how to look this up, but I'm not finding the solution
I have a problem with internet explorer 6 and 7, please look this example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.