...

View Full Version : Cant get radio button values!



ScottInTexas
07-08-2004, 08:06 PM
All I want to do is see what value is set. Of course everything I try has failed.

In my form I have
<form method="POST" action="pending_approval_process.asp" name="approvers" onsubmit="return NotifyUser()">

<input type="radio" name="status" value="Approved" >Approved
<input type="radio" name="status" value="NotApproved" >Do Not Approve
<input type="submit" value="Submit" name="B1">

And NotifyUser is


function NotifyUser(){
alert(" this is " + approvers.status.value);
alert(approvers.nextlevel.value=="true" && approvers.status.value!="NotApproved");
return false;
}


the first alert always returns "this is undefined" and the second a;lert always returns true. I have purposely put return false in there to jump out of the routine and not execute the rest of the notifyuser rotuine. How the %$#@ do I look at the value? In the asp that gets called I just want to access the status value.

Thanks

Willy Duitt
07-08-2004, 08:21 PM
You need to loop thru the radio buttons to see which one is checked. A search of this forum will provide numerous examples of how this is done....

jamescover
07-09-2004, 12:18 AM
function NotifyUser(){

if (approvers.status[0].checked){
alert("this is " + approvers.status[0].value);
return false;
}
if (approvers.status[1].checked){
alert ("this is " + approvers.status[1].value);
return false;
}
}







-james

Vincent Puglia
07-09-2004, 03:47 PM
Hi,

Any group of elements that have the same name are considered an array -- this is true whether the language is javascript, asp, php, or C. As Willy said, they must be looped. james's code avoids by specifically querying the individual elements -- a technique that is practical only if 2 buttons are used (more and it gets messy)

James:

if (approvers.status[0].checked)
alert("this is " + approvers.status[0].value);
else
alert ("this is " + approvers.status[1].value);
return false;

there is no need for an addition if statement with 2 -- buttons are either on/off -- because one should be set checked initially.
Also, if you're going to return false for both -- do it at the end, less code, more elegance :D

Hi Willy :D

Vinny

jamescover
07-09-2004, 07:13 PM
james's code avoids by specifically querying the individual elements -- a technique that is practical only if 2 buttons are used (more and it gets messy)

there is no need for an addition if statement with 2 -- buttons are either on/off -- because one should be set checked initially.

I plead innocent on these--his example had only 2 radio buttons and neither checked :D

I suppose, I could have rewritten using the best way...


Also, if you're going to return false for both -- do it at the end, less code, more elegance

Guilty, your Honor...can you teach elegance...ha ha.

I'm just learning myself, so teach away...



-james

Vincent Puglia
07-09-2004, 07:27 PM
Hi james :D

And here I thought I was writing the comments more for Scott :)

Elegance: the opposite of spaghetti-code. Never think the code is good until some time has passed. If you can still decipher what you did and it still looks good and you can't think of how to improve it -- it's time to buy a book or find another coder :D

Elegance is something everyone strives for, but rarely gets. If you really want to learn how -- grab somebody else's code & cut it in half (dreamweaver code don't count, but it's a good starting point. :D

google my name & willy's (he's got some good looking code out there :) -- the code examples may not always be elegant, but they'll help teach
also, http://members.aol.com/grassblad <-- an old site of mine (scripts with explanations) that AOL was supposed to tear down months ago

Vinny

Willy Duitt
07-09-2004, 07:58 PM
Thank you for the compliment Vinny! :thumbsup:

Your advise about taking code apart is certainly good advice because what I know I have learned from doing just that. And your code is one of the first I started to take apart. :D

.....Willy

Vincent Puglia
07-09-2004, 08:00 PM
Sure pick on the old man :(

:cool:
Vinny



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum