SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Dec 14, 2009, 07:17 #1
- Join Date
- Jan 2007
- Posts
- 130
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
How Do I Populate a Hidden Input Field?
Hi, here's the code that I've written that doesn't work, please have a look at it because it'll help you understand what I want to do...
HTML Code:<script language="JavaScript" type="text/javascript"> //function that should populate the hidden field function popGender(val) { switch (val) { case '16130': case '16132': case '16133': gender = 3143; //female break; case '16131': gender = 3142; //male break; } document.ghm_form.q434.value = gender; } </script> <!-- Title - this field is supposed to use it's data to populate the gender field below --> <select name="q1004" onchange="popGender(this.value)"> <option value="">--Select One-- <option value="16130">Miss <option value="16131">Mr. <option value="16132">Mrs. <option value="16133">Ms. </select> <!-- Gender (should be populated when title is selected) --> <input type="hidden" name="q434" value="">
-
Dec 14, 2009, 07:32 #2
- Join Date
- Mar 2006
- Location
- Yorkshire, UK
- Posts
- 528
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if you give it an id, then you could use
Code JavaScript:document.getElementById(id).value = gender;
Technology is dominated by two types of people:
those who understand what they do not manage,
and those who manage what they do not understand.
-
Dec 14, 2009, 07:36 #3
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You should also make sure gender is a string value, not a number, since input field values are strings.
Code JavaScript:function popGender(val) { switch (val) { case '16130': case '16132': case '16133': gender = "3143"; //female break; case '16131': gender = "3142"; //male break; } document.getElementById("q434").value = gender; }
Code HTML4Strict:<input type="hidden" name="q434" id="q434" value="">
Birnam wood is come to Dunsinane
-
Dec 14, 2009, 10:54 #4
- Join Date
- Jan 2007
- Posts
- 130
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Thanks, I'll have a look at that.
Bookmarks