Jump to content

Radio input Javascipt


Cod-nes

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>

Link to comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...