Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-24-2005, 11:54 PM
  #1
mngmd
Novice (Level 1)
 
Join Date: Sep 2005
Posts: 3
iTrader: (0)
mngmd is an unknown quantity at this point
Radio button problem

This should be easy, but I'm a complete newbie.

I've figured out combo boxes, but I want to use radio buttons to allow for selections. I'm using only javascript...

IN the body, I have:

<FORM NAME="test" ONSUBMIT="return setfilen(this)">
<P><INPUT TYPE="RADIO" NAME="cal" VALUE="Nov" CHECKED />November 6 thru December 3<br></P>
<P><INPUT TYPE="RADIO" NAME="cal" VALUE="Nov_" />December 4 thru December 31</P>

In the script itself, I have

function setfilen (form) {
alert (form.cal.value)}

Works fine when there's only one radio button, but as soon as I add a second, I get "Undefined". (This is primitive, I know). What am I doing wrong?
mngmd is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-25-2005, 02:42 AM
  #2
birdbrain
Paladin (Level 15)
 
Join Date: Sep 2005
Location: I have a bijou perch
Posts: 314
iTrader: (0)
birdbrain is an unknown quantity at this point
Hi mngmd,

try this, it will work for any number of inputs with the same name...
Code:
<script type="text/javascript">
<!--
function setfilen () {
  var inps=document.getElementsByTagName('input');
for(i=0;i<inps.length;i++) {
if(inps[i].name=='cal') {
  alert (inps[i].value);
  }
 }
}
//-->
</script>

<form  action="#" name="test" onsubmit="return setfilen()">
<div>
<input type="radio" name="cal" value="Nov" CHECKED />November 6 thru December 3<br />
<input type="radio" name="cal" value="Nov_" />December 4 thru December 31</br />
<input type="submit"/>
</div>
</form>
reson for edit....pore speling

Last edited by birdbrain : 09-25-2005 at 12:35 PM.
birdbrain is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-25-2005, 12:05 PM
  #3
mngmd
Novice (Level 1)
 
Join Date: Sep 2005
Posts: 3
iTrader: (0)
mngmd is an unknown quantity at this point
OK.

But how do I get it to tell me which one is checked?

Thanks in advance.
mngmd is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-25-2005, 01:01 PM
  #4
birdbrain
Paladin (Level 15)
 
Join Date: Sep 2005
Location: I have a bijou perch
Posts: 314
iTrader: (0)
birdbrain is an unknown quantity at this point
Hi mngmd,
Quote:
But how do I get it to tell me which one is checked?
  1. The one that is checked will have it's value submitted.
  2. The one that is checked has a a small black dot.
  3. If that is still insufficient evidence for your needs then
    you can have an alert to give you this information.
Try this code it will show you all three options...
Code:
<script type="text/javascript">
<!--
function setfilen () {
  var inps=document.getElementsByTagName('input');
for(i=0;i<inps.length;i++) {
if((inps[i].name=='cal')&&(inps[i].checked==true)) {
  alert ('the radio button checked is number '+(i+1)+'\n\n and it\'s value= '+inps[i].value);
  }
 }
}
//-->
</script>

<form name="test" action="http://www.google.com" method="get"onsubmit="return setfilen()">
<div>
<input type="radio" name="cal" value="Nov" checked="checked" />November 6 thru December 3<br />
<input type="radio" name="cal" value="Nov_" />December 4 thru December 31<br />
<input type="submit"/>
</div>
</form>
I trust that this will satisfy all of your requirements.
birdbrain is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:30 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.