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

radion buttons and forms...

Status
Not open for further replies.

indigoblue

Programmer
Sep 7, 2000
9
GB
Hi am trying to code a page where a user selects a radio box and depending on what option is selected, the user is redirected to another page, with certain values that depend on what is selected posted to the next page. The html goes like this:

<form name=&quot;form1&quot; action=&quot;pagex.htm&quot; onSubmit=&quot;return transvar(this)&quot;>

<input type=&quot;radio&quot; value=&quot;r0&quot; name=&quot;mselect&quot;></p>
<input type=&quot;radio&quot; value=&quot;r1&quot; name=&quot;mselect&quot;></p>

<input type=&quot;hidden&quot; name=&quot;var1&quot;>
<input type=&quot;hidden&quot; name=&quot;var2&quot;>

<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>

</form>

and the transvar code I've written as follows:

function transvar(form)
{

if(form.mselect[0].checked == true)
{
form.var1.value = &quot;xxx&quot;;
form.var2.value = &quot;yyy&quot;;
return true;
}
else if(form.mselect[1].checked == true)
{
form.var1.value = &quot;zzz&quot;;
form.var2.value = &quot;aaa&quot;;
return true;
}
......
}


but, whenever I click submit I get an &quot;object expected&quot; error message.
Has anyone got any ideas?

Cheers,
Paul [sig][/sig]
 
I am not really sure about Javascript, but I know in VBScript, a radio button that is clicked returns the value in &quot;Value&quot; For eg, if first button is clicked, mselect would be equal to r0. Therefore, you should check what mselect.value is equal to.

[sig][/sig]
 
Hi,

Try:

<form name=&quot;form1&quot; action=&quot;pagex.htm&quot; onSubmit=&quot;return transvar(document.forms.form1)&quot;>

OR

<form name=&quot;form1&quot; action=&quot;pagex.htm&quot; onSubmit=&quot;return transvar(document.forms['form1'])&quot;>

I've only tested it in IE 4 and they both work, but not sure about netscape. You need to refer to the form in some way (i.e. this.form). However, 'this.form' doesn't even work in this case. I'm a bit confused at this myself, maybe someone else can explain why this is so.

Also, make sure that you return 'false' when the user selects neither value to prevent the form from submitting (assuming this is what you want to do).

Regards, [sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top