How to submit a form on a radio click

H

HD

Hi.

I have an asp page with radio buttons and a combobox... when the user clicks
a radio button, I want the form to submit so I can execute the ASP code in
order to change the list shown in the combobox... I have 2 radiobuttons:

<input type="radio" name="terriprod" value="E">E
<input type="radio" name="terriprod" value="D">D

I have tried adding an OnClick event to each of the radio button...
<input type="radio" name="terriprod" value="D"
onclick="Javascript:document.forms[0].submit();">D
but it does not work...

I have then tried to put each of the radio button into an anchor...
<a href="Javascript:document.forms[0].submit();"><input type="radio"
name="terriprod" value="D"></a>D
but it does not work...

I have then tried to add to the onclick event a javascript function
<input type="radio" name="terriprod" value="D"
onclick="Javascript:Verif(document.forms[0]);">D
and in the Verif function I try to submit the form but it does not work...

I have also tried:
I have then tried to add to the onclick event a javascript function
<input type="radio" name="terriprod" value="D" onclick="Javascript:if
Verif(document.forms[0]) {document.forms[0].submit();};">D

But it does not work...

Can someone help me.

HDumas
 
L

lallous

Hello

Try this: <input type="radio" name="terriprod" value="D"
onclick="this.form.submit();">D

Anyway, the onclick events you added should work as well...What browser
you're using?
Perhaps you have other script errors in your page...
 
H

HD

Hi and thanks but I have tried your suggestion...it does not work... it does
submit the form, but it does not go through the Verif function.
When the user clicks on the radio button, I need it to do the Verif function
and then submit the form.

..... I have Internet Explorer on Windows XP...


lallous said:
Hello

Try this: <input type="radio" name="terriprod" value="D"
onclick="this.form.submit();">D

Anyway, the onclick events you added should work as well...What browser
you're using?
Perhaps you have other script errors in your page...

--
Elias
HD said:
Hi.

I have an asp page with radio buttons and a combobox... when the user
clicks
a radio button, I want the form to submit so I can execute the ASP code in
order to change the list shown in the combobox... I have 2 radiobuttons:

<input type="radio" name="terriprod" value="E">E
<input type="radio" name="terriprod" value="D">D

I have tried adding an OnClick event to each of the radio button...
<input type="radio" name="terriprod" value="D"
onclick="Javascript:document.forms[0].submit();">D
but it does not work...

I have then tried to put each of the radio button into an anchor...
<a href="Javascript:document.forms[0].submit();"><input type="radio"
name="terriprod" value="D"></a>D
but it does not work...

I have then tried to add to the onclick event a javascript function
<input type="radio" name="terriprod" value="D"
onclick="Javascript:Verif(document.forms[0]);">D
and in the Verif function I try to submit the form but it does not work...

I have also tried:
I have then tried to add to the onclick event a javascript function
<input type="radio" name="terriprod" value="D" onclick="Javascript:if
Verif(document.forms[0]) {document.forms[0].submit();};">D

But it does not work...

Can someone help me.

HDumas
 
R

Randy Webb

HD said:
Hi and thanks but I have tried your suggestion...it does not work... it does
submit the form, but it does not go through the Verif function.
When the user clicks on the radio button, I need it to do the Verif function
and then submit the form.

Then call the Verif function and let Verif submit the form.

<form onsubmit="Verif();return false">

And then in Verif, submit the form.
..... I have Internet Explorer on Windows XP...

And your point is?
 
R

Rob B

You haven't posted your HTML (or enough of it) so, a guess: this usually
happens when someone does this -

<input type="submit" name="submit" />

...which over-writes the Form.submit() method. If so, just name that
button something else.
 
R

Randy Webb

Rob said:
You haven't posted your HTML (or enough of it) so, a guess: this usually
happens when someone does this -

<input type="submit" name="submit" />

...which over-writes the Form.submit() method. If so, just name that
button something else.

Let me quote part of the OP's response for you:

<quote>
Hi and thanks but I have tried your suggestion...it does not work... it
does submit the form, but it does not go through the Verif function.
</quote>

The form submits, but the form's onsubmit handler doesn't get called.
That is documented behavior. The solution, thats in my last post, is to
have the validation function submit the form and then call the
validation function onclick as well as onsubmit.
 
R

Rob B

Randy said:
The form submits, but the form's onsubmit handler doesn't get called.
That is documented behavior.

Thanks, I knew that - but where do you see, in the above, any trace of
an onsubmit handler (or a form tag, for that matter)?

Can you explain this:
I have then tried to add to the onclick event a javascript function
<input type="radio" name="terriprod" value="D"
onclick="Javascript:Verif(document.forms[0]);">D
and in the Verif function I try to submit the form but it > does not work...

I have also tried:
I have then tried to add to the onclick event a javascript function
<input type="radio" name="terriprod" value="D" onclick="Javascript:if
Verif(document.forms[0]) {document.forms[0].submit();};">D
But it does not work...

As HDumas noted, they should have. The only way explicitly calling
Form.submit() will fail is if the method itself is over-written, a
common occurrence as a result of naming the submit button "submit". Yes,
I noticed he said "it does
submit the form..." but thought he might be mistaken as there is no
other likely explanation for the earlier observations.
The solution, thats in my last post...

Not necessarily the only one....

<form.....onsubmit="return Verif(this)">
<input type="radio" name="terriprod" value="E" />E
<input type="radio" name="terriprod" value="D"
onclick="if(Verif(this.form))this.form.submit()" />D
<input type="submit" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top