Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 162567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:24:50+00:00 2026-05-11T11:24:50+00:00

I am basing my question and example on Jason’s answer in this question I

  • 0

I am basing my question and example on Jason’s answer in this question

I am trying to avoid using an eventListener, and just to call handleClick onsubmit, when the submit button is clicked.

Absolutely nothing happens with the code I have.

Why is handleClick not being called?

<html>   <head>     <script type='text/javascript'>       function getRadioButtonValue(rbutton)       {         for (var i = 0; i < rbutton.length; ++i)         {            if (rbutton[i].checked)             return rbutton[i].value;         }         return null;       }        function handleClick(event)       {         alert('Favorite weird creature: '+getRadioButtonValue(this['whichThing']));         event.preventDefault(); // disable normal form submit behavior         return false; // prevent further bubbling of event       }     </script>   </head> <body>     <form name='myform' onSubmit='JavaScript:handleClick()'>       <input name='Submit'  type='submit' value='Update' onClick='JavaScript:handleClick()'/>       Which of the following do you like best?       <p><input type='radio' name='whichThing' value='slithy toves' />Slithy toves</p>       <p><input type='radio' name='whichThing' value='borogoves' />Borogoves</p>       <p><input type='radio' name='whichThing' value='mome raths' />Mome raths</p>     </form> </body> </html> 

edit:

Please do not suggest a framework as a solution.

Here are the relevant changes I have made to the code, which results in the same behavior.

      function handleClick()       {         alert('Favorite weird creature: '+getRadioButtonValue(document.myform['whichThing'])));         event.preventDefault(); // disable normal form submit behavior         return false; // prevent further bubbling of event       }     </script>   </head> <body> <form name='aye'>;       <input name='Submit'  type='submit' value='Update' action='JavaScript:handleClick()'/>       Which of the following do you like best?       <p><input type='radio' name='whichThing' value='slithy toves' />Slithy toves</p>       <p><input type='radio' name='whichThing' value='borogoves' />Borogoves</p>       <p><input type='radio' name='whichThing' value='mome raths' />Mome raths</p>     </form> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:24:51+00:00Added an answer on May 11, 2026 at 11:24 am

    In this bit of code:

    getRadioButtonValue(this['whichThing'])) 

    you’re not actually getting a reference to anything. Therefore, your radiobutton in the getradiobuttonvalue function is undefined and throwing an error.

    EDIT To get the value out of the radio buttons, grab the JQuery library, and then use this:

      $('input[name=whichThing]:checked').val()  

    Edit 2 Due to the desire to reinvent the wheel, here’s non-Jquery code:

    var t = ''; for (i=0; i<document.myform.whichThing.length; i++) {      if (document.myform.whichThing[i].checked==true) {          t = t + document.myform.whichThing[i].value;      } } 

    or, basically, modify the original line of code to read thusly:

    getRadioButtonValue(document.myform.whichThing)) 

    Edit 3 Here’s your homework:

          function handleClick() {         alert('Favorite weird creature: ' + getRadioButtonValue(document.aye.whichThing));         //event.preventDefault(); // disable normal form submit behavior         return false; // prevent further bubbling of event       }     </script>   </head> <body> <form name='aye' onSubmit='return handleClick()'>      <input name='Submit'  type='submit' value='Update' />      Which of the following do you like best?      <p><input type='radio' name='whichThing' value='slithy toves' />Slithy toves</p>      <p><input type='radio' name='whichThing' value='borogoves' />Borogoves</p>      <p><input type='radio' name='whichThing' value='mome raths' />Mome raths</p> </form> 

    Notice the following, I’ve moved the function call to the Form’s ‘onSubmit’ event. An alternative would be to change your SUBMIT button to a standard button, and put it in the OnClick event for the button. I also removed the unneeded ‘JavaScript’ in front of the function name, and added an explicit RETURN on the value coming out of the function.

    In the function itself, I modified the how the form was being accessed. The structure is: document.[THE FORM NAME].[THE CONTROL NAME] to get at things. Since you renamed your from aye, you had to change the document.myform. to document.aye. Additionally, the document.aye[‘whichThing’] is just wrong in this context, as it needed to be document.aye.whichThing.

    The final bit, was I commented out the event.preventDefault();. that line was not needed for this sample.

    EDIT 4 Just to be clear. document.aye[‘whichThing’] will provide you direct access to the selected value, but document.aye.whichThing gets you access to the collection of radio buttons which you then need to check. Since you’re using the ‘getRadioButtonValue(object)’ function to iterate through the collection, you need to use document.aye.whichThing.

    See the difference in this method:

    function handleClick() {    alert('Direct Access: ' + document.aye['whichThing']);    alert('Favorite weird creature: ' + getRadioButtonValue(document.aye.whichThing));    return false; // prevent further bubbling of event } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm basing my question on this one: rspec mocks: verify expectations in it "should"
I'm trying to create a new module for Sitefinity. I'm basing my module off
Telerik's RADGrid, basing on their example on http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/programaticlinqupdates/defaultcs.aspx Problem: I can insert and delete,
one question about NDBCLUSTER. I inherited the writing of a web site basing on
I'm heavily basing my code off of this excellent tutorial at Ars Technica, so
I'm creating a custom UI using the piwik API too call the various modules.
This question is prompted by the rather militant refusal of developer Michael Rys to
Probably a noob question but interop isn't one of my strong points yet. Aside
I am using a thread to capture stream output from a process, and then
I am developing an OpenID consumer in PHP and am using the fantastic LightOpenID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.