www.webdeveloper.com
Results 1 to 9 of 9

Thread: Stuck on radio.checked, should be simple

  1. #1
    Join Date
    Aug 2012
    Posts
    4

    Unhappy Stuck on radio.checked, should be simple

    I'm trying to pass a variable gathered from a radio button and all day i've been stuck on something that seems so small, maybe i've been staring too long.

    No matter what radio that is checked it's resulting as 0.

    Here's the button
    Code:
    <div ID="dCloneTypeSelect" name="dCloneTypeSelect" style="border: 1px solid black; padding: 0px; position: absolute; visibility: hidden;"">
    <table bgcolor="#ffffff">
    <tr>
    <td>
    <span style="color:black; font-family:verdana; font-size:8pt; font-weight:normal">
    <b>How would you like to clone?</b><br>
    <input type=radio id = "rdoClonewHours" name="CloneSelect" value="0" > Clone with Hours <br>
    <input type=radio id = "rdoCloneNoHours" name="CloneSelect" value="1" > Clone without Hours <br></span> 
    <center>
    <input type=button value="Clone" style="font-size: 8pt;" onclick="CloneFromTypeSelect()" id=button1 name=button1>&nbsp;&nbsp;&nbsp;<input type=button value="Cancel" style="font-size: 8pt;" onclick="HideCloneTypeSelect('btnClone')" id=button2 name=button2><br>
    </center>
    </td>
    </tr>
    </table>
    </div>
    Then where i'm trying to get and set selected.
    Code:
    function GetCloneType()
    {
    var CloneType = 0;
    if (document.getElementById("rdoClonewHours").checked)
    CloneType = 0;
    else if (document.getElementById("rdoCloneNoHours").checked)
    CloneType = 1;
    				
    //alert (CloneType);
    return CloneType;
    }
    Then where i am trying to use the type. Which works if i can get 0 or 1, it's the function above that needs work.

    Code:
    function CloneTS()
    {
    var CloneSelect = GetCloneType()
    			
    if (CloneSelect == 0)
    			
    {
    var confirm_clonewhours = confirm ("You are cloning codes and hours from last pay period, not including any leave hours, do you wish to continue?");
    if (confirm_clonewhours == false)
    {
    document.getElementById("dCloneTypeSelect").style.visibility = 'visible';
    document.getElementById("rdoClonewHours").checked = true;
    }
    }
    else if (CloneSelect == 1)
    {
    var confirm_clonenohours = confirm ("You are cloning codes only from last pay period, not including any leave codes, do you wish to continue?");
    if (confirm_clonenohours == false)
    {
    document.getElementById("dCloneTypeSelect").style.visibility = 'visible';
    document.getElementById("rdoCloneNoHours").checked = true;
    }
    }
    }
    No matter what i modify i keep getting 0, suggestions?!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    Try this...
    Code:
    function GetCloneType() {
      var CloneType;
      if (document.getElementById("rdoClonewHours").checked) { CloneType = 0; }
      if (document.getElementById("rdoCloneNoHours").checked) { CloneType = 1; }
    //alert (CloneType);
      return CloneType;
    }
    Not the way I would do it, but trying to keep with your code logic.

  3. #3
    Join Date
    Aug 2012
    Posts
    4
    alert returns undefined, if i define as 0 again, same thing...keeps setting to 0
    ...i'm open to changes, i myself was trying to modify an already existing app in which this is working elsewhere but the code is so mixed everywhere it's hard to insert new stuff

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    Where are the functions "CloneFromTypeSelect()" and "HideCloneTypeSelect()" located?

    How do you display the choices when you start with CSS visibility:hidden ?

    Do you have a link to a live site where we can see what other errors are being generated?

  5. #5
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,096
    Put it in a jsfiddle

    Http://jsfiddle.net

    Then we can easily play with it live and send you a link to the fixed code.

  6. #6
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,096
    http://jsfiddle.net/H25Gs/


    Sorry... Can't help with my ipad ... Scripts aren't running on it...
    :-(

  7. #7
    Join Date
    Aug 2012
    Posts
    4
    CloneFromTypeSelect just says if nothing is selected when hitting the button alert and HideFromTypeSelect just hides the div table.

  8. #8
    Join Date
    Aug 2012
    Posts
    4

    resolved [RESOLVED] Stuck on radio.checked, should be simple

    Ugh i figured this out, told you it was stupid, i moved the call to HideCloneTypeSelect to the end of the CloneTS function, everytime i was hiding i was resetting the checkboxes to false hence always returning 0.
    Last edited by ckline039; 08-15-2012 at 02:42 PM. Reason: Resolved

  9. #9
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Arrow

    Quote Originally Posted by ckline039 View Post
    Ugh i figured this out, told you it was stupid, i moved the call to HideCloneTypeSelect to the end of the CloneTS function, everytime i was hiding i was resetting the checkboxes to false hence always returning 0.
    Well, that helps explain why we needed to see the rest of the code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles