Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Cant get radio button values!

    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
    Code:
    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
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by jamescover; 07-09-2004 at 01:20 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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

    Hi Willy

    Vinny
    Where the world once stood
    the blades of grass
    cut me still

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    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
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #6
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Hi james

    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

    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.

    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
    Where the world once stood
    the blades of grass
    cut me still

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the compliment Vinny!

    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.

    .....Willy

  • #8
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Sure pick on the old man


    Vinny
    Where the world once stood
    the blades of grass
    cut me still


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •