How to submit a form on a radio click

Discussion in 'Javascript' started by HD, Nov 19, 2004.

  1. HD

    HD Guest

    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
    HD, Nov 19, 2004
    #1
    1. Advertising

  2. HD

    lallous Guest

    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" <> wrote in message
    news:Dnnnd.43498$...
    > 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
    >
    >
    lallous, Nov 19, 2004
    #2
    1. Advertising

  3. HD

    HD Guest

    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" <> a écrit dans le message de
    news:...
    > 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" <> wrote in message
    > news:Dnnnd.43498$...
    > > 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
    > >
    > >

    >
    >
    HD, Nov 19, 2004
    #3
  4. HD

    Randy Webb Guest

    HD wrote:
    > 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?

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Nov 19, 2004
    #4
  5. HD

    Rob B Guest

    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.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Rob B, Nov 19, 2004
    #5
  6. HD

    Randy Webb Guest

    Rob B wrote:
    > 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.


    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Nov 19, 2004
    #6
  7. HD

    Rob B Guest

    Randy Webb wrote:
    > 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" />


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Rob B, Nov 20, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page