Jump to content

Radio input Javascipt


Recommended Posts

I'm trying to get the value for radios using JavaScript but I keep getting undefined values. >.< What am I doing wrong? :)

function checka() { var a = document.seaform.searadx; alert(a);} <form name="seaform" action="java script: msgsea()" method="get"> <div style="margin-bottom:4px;">Search for username: <input type="text" id="search" maxlength="12" size="12" onkeyup="msgsea()"> <a href="java script: msgsea();">Search</a> <br> That begins with the keyword: <input type="radio" name="searadx" value="begins" checked="checked"><br> That contains the keyword: <input type="radio" name="searadx" value="contains"><br> That ends with the keyword: <input type="radio" name="searadx" value="ends"> <a href="java script:checka()">Test Value</a> </div></form>

Edited by Cod-nes
Link to post
Share on other sites

I don't recommend doing this with dot notation, but try this:var a = document.seaform.searadx.value;If you're interested in modernizing this code you should look up the getElementsByName function and use that to populate an array, which you would then loop through to see which radio is checked and return its value.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...