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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Hidden values 2

Status
Not open for further replies.

bjohnson

Programmer
May 3, 2001
4
US
I am a novice user of javascript and am trying to solve the following dilemma (I apologize if this is extraordinarily basic):

I have a form that has checkboxes on it. If the user changes the values of the checkbox (from either checked to unchecked or from unchecked to checked), I would like to pass that value to a URL. That's the easy part. Where I am running into trouble is I also want to create a hidden value that is passed to the URL as well, but ONLY if the value has changed.

I created a Hidden input type associated with the checkbox, but the problem is, these values always appear on the URL, no matter if the checkbox was changed or not. I only want that hidden value to pass if the checkbox was changed.

<FORM ACTION=&quot;form1.html&quot; METHOD=&quot;post&quot; NAME=&quot;form2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;row&quot; VALUE=&quot;Yes&quot; ONCHANGE=&quot;checkbuttons()&quot;>
<INPUT TYPE=&quot;Hidden&quot; NAME=&quot;row&quot; VALUE=&quot;Hidden&quot;>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot;>

I assume I need to create a function in Javascript called checkbuttons(), but that's where I'm stuck. Where do I go from here? Any ideas?
 
create a function which is triggered, only if this radio is pressed, mind you, it doesn't matter if you send values to your action and not use them, no harm is done. If you have a hidden value, it WILL be sent with the rest if your form, all form values are, it just depends what values are sent.So where yopu receive the form values just allow for the 'empty ' value.

Or you could dynamically write new hidden fields into the form.
b2 - benbiddington@surf4nix.com
 
Could I write logic into the &quot;triggered&quot; function that will then create the hidden fields (i.e. - if this function is triggered, create a hidden field)? Is that possible in Javascript? I thought about something like

function checkbuttons() {
document.write(&quot;'<input type=&quot;hidden&quot; name=&quot;row&quot; value=&quot;hidden&quot;>')




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top