SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: prepopulate radio button
-
Sep 28, 2006, 15:19 #1
- Join Date
- Aug 2006
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
prepopulate radio button
This script prepopulates select box, state, but not radio button, tobacco.
Code:<script language="javascript" type="text/javascript"> function prepop() { document.long_form.state.value="<?php echo $_SESSION['state']; ?>"; document.long_form.tobacco.value="<?php echo $_SESSION['tobacco']; ?>"; } window.onload=prepop; </script>
Any suggestions?
-
Sep 28, 2006, 15:59 #2
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
document.long_form.tobacco.checked = true;
-
Sep 28, 2006, 16:19 #3
- Join Date
- Aug 2006
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for your reply, jimfraser.
Adding that line to the javascript made no difference.
Is there something else that should be done?
-
Sep 28, 2006, 18:37 #4
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
It should be:
document.long_form.tobacco[0].checked = true;
or if that doesn't check the right one then change the number between the [] to one less than the one that should be checked.Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Sep 28, 2006, 19:28 #5
- Join Date
- Aug 2006
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you, felgall.
Now at least one of the buttons shows as being checked on the receiving page.
However, whether it should be yes or no depends on what the visitor checks in the first (short) form. The value is being passed for visitor convenience in case they also want to complete the long form.
The value is received using
Code:document.long_form.tobacco.value="<?php echo $_SESSION['tobacco']; ?>";
I tried a few alternatives based on your suggestion, but none have worked so far.
-
Sep 28, 2006, 22:36 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Try this (not sure if it will work and not where i can test it at the moment):
document.long_form.tobacco["<?php echo $_SESSION['tobacco']; ?>"].checked = true;Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Sep 28, 2006, 23:36 #7
- Join Date
- Aug 2006
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
felgall, that was one of the alternatives I had tried.
It does not work because the value it delivers is either 'yes' or 'no' whereas the value needs to be either '0' or '1'' as explained in your previous reply.
Here is the solution:
Code:var tob; var tabac="<?php echo $_SESSION['tobacco']; ?>"; { if (tabac=="yes") {tob="0"} else if (tabac=="no") {tob="1"} document.long_form.tobacco[tob].checked = true;
Resolved!
Bookmarks