Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the hidden values based on img clicked

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
I have 3 images.

When I click on the first image the hidden values should be:

<input type="hidden" name="item" value="Hello">
<input type="hidden" name="code" value="123">
<input type="hidden" name="amount" value="$19.99">

When I click on the second image the hidden values change to:

<input type="hidden" name="item" value="Good afternoon">
<input type="hidden" name="code" value="468">
<input type="hidden" name="amount" value="$29.99">

When I click on the third image the hidden values change to:

<input type="hidden" name="item" value="Good night">
<input type="hidden" name="code" value="579">
<input type="hidden" name="amount" value="$1129.99">


How can I do this when I click the Submit button?
 
Using the Onclick event of the images, and chekcing which image was used:

Code:
<script>
function set_Hidden_Values(imgObj){
  if(imgObj.name=="image1"){
    document.forms.myform.item.value="Hello";
    document.forms.myform.code.value="123";
    document.forms.myform.amount.value="19.99";
}

  if(imgObj.name=="image2"){
    document.forms.myform.item.value="Good Afternoon";
...
}

  if(....){
...
}
}


<img src="myimage.jpg" name="image1" OnClick="set_Hidden_Values(this);">
<img src="otherimage.jpg" name="image2" ...>
...

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi

Personally I prefer to store the data in a structured format, instead of spreading it across multiple control structures :
JavaScript:
[b]var[/b] clickval[teal]=[/teal][teal]{[/teal]
  [green][i]'image1'[/i][/green][teal]:[/teal][teal]{[/teal] [green][i]'item'[/i][/green][teal]:[/teal][green][i]'Hello'[/i][/green][teal],[/teal]          [green][i]'code'[/i][/green][teal]:[/teal][purple]123[/purple][teal],[/teal] [green][i]'amount'[/i][/green][teal]:[/teal][green][i]'$19.99'[/i][/green] [teal]}[/teal][teal],[/teal]
  [green][i]'image2'[/i][/green][teal]:[/teal][teal]{[/teal] [green][i]'item'[/i][/green][teal]:[/teal][green][i]'Good afternoon'[/i][/green][teal],[/teal] [green][i]'code'[/i][/green][teal]:[/teal][purple]468[/purple][teal],[/teal] [green][i]'amount'[/i][/green][teal]:[/teal][green][i]'$29.99'[/i][/green] [teal]}[/teal][teal],[/teal]
  [green][i]'image3'[/i][/green][teal]:[/teal][teal]{[/teal] [green][i]'item'[/i][/green][teal]:[/teal][green][i]'Good night'[/i][/green][teal],[/teal]     [green][i]'code'[/i][/green][teal]:[/teal][purple]579[/purple][teal],[/teal] [green][i]'amount'[/i][/green][teal]:[/teal][green][i]'$1129.99'[/i][/green] [teal]}[/teal]
[teal]}[/teal]

[b]function[/b] [COLOR=darkgoldenrod]set_Hidden_Values[/color][teal]([/teal]imgObj[teal])[/teal]
[teal]{[/teal]
  [b]for[/b] [teal]([/teal][b]var[/b] one [b]in[/b] clickval[teal][[/teal]imgObj[teal].[/teal]name[teal]])[/teal]
    document[teal].[/teal]myform[teal][[/teal]one[teal]].[/teal]value[teal]=[/teal]clickval[teal][[/teal]imgObj[teal].[/teal]name[teal]][[/teal]one[teal]][/teal]
[teal]}[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top