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

hidden input, same name as radion input 2

Status
Not open for further replies.

dpcooke

Programmer
Jan 18, 2008
2
US
Hello I have an site where a user can select 4 options from a radio button, and then submit the form.

I would like them to also be able to click a link or button which automaticially behaves as if they had selected the 3rd radio button.

I do not control the interface on the other side so i have to pass this as if they had selected that radio button.

Is this possible?
If so how?
Thanks
 
You'll need Javascript for this: take this example for now, but if you want a more detailed solution I suggest asking in the forum216.

Code:
<form action="radios.php" method="POST" name="myform">

<input type=radio name="choice[]" value="choice1">
<input type=radio name="choice[]" value="choice2">
<input id="choice3" type=radio name="choice[]" value="choice3">
<input type=radio name="choice[]" value="choice4">

</form>
<button onClick="document.getElementById('choice3').checked=true;">Select Radio 3</button>

Notice how i put the button outside the form, otherwise the button will select the 3rd radiobutton and immediately submit the form when its pressed.

----------------------------------
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.
 
Well why?
Radio buttons are for select only one value. Or you can use the checkboxes.. Or just add a hidden input which saves any other values so that you ASP/PHP gets it.

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Well its for an ecommerce type thing. You can select options like color
blue
red
green

And then say buy.

But then i want them to be able to click on a suggested configuretion link and then no matter what they have selected for the radio button its green...

The problem is i don't control the page that the form submits to so it has to be as if the radio button with the same name is checked....
 
Aha..
Then add an ID to each radio and access them by that and check it.

[tab]HTML:

Code:
[purple]<form>
<input name="myradio" value="one" />
<input id="two" name="myradio" value="two" />
<input name="myradio" value="three" />
<input type="button" value="Check radio \"two\"" onclick="[navy]document.getElementById('two').checked = true;[/navy]" />
</form>[/purple]


- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Did you just copy and paste that from Vacunita's earlier answer? Or did you just not read the thread before posting?

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Sorry, I was too fast looking though the posts. Didn't see that [navy]Vacunita[/navy] also used the ID.. It's my bad.

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Ppppffffttttt SW.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top