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 4 of 4

Thread: radio buttons

  1. #1
    New Coder
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    1
    Thanked 1 Time in 1 Post

    radio buttons

    [code]
    function timeToCall() {

    var calltime = document.getElementsByName("timetocall");

    for (var x = 0; x < calltime.length; x++) {
    if (calltime.checked == true) {
    return true;
    } else {
    producePrompt("Please select an appropriate time for us to contact you", "timePrompt", "red");
    return false;

    }
    }
    }
    [\code]

    the problem I am having is that according to fire bug the above function does not always return a value. can anybody help me solve this problem? and thank you in advance to anyone who may be able to help

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Code:
     
     function timeToCall() {
            var calltime = document.getElementsByName("timetocall");
            for (var x = 0; x < calltime.length; x++) {
                if (calltime[x].checked == true) {
                    //success producePrompt goes here
                    return true;
                } 
           }
           producePrompt("Please select an appropriate time for us to contact you", "timePrompt", "red");
           return false;       
     }
    If you don't understand why
    the changes I made were
    necessary I will be glad to
    explain in detail.
    Last edited by DaveyErwin; 12-31-2013 at 01:47 AM.

  • #3
    New Coder
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    1
    Thanked 1 Time in 1 Post
    I have tried this but it does not seem to make any difference and I don't know why.

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Maybe you have a problem
    somewhere else ?

    Try this stripped down version ...

    Code:
     
    <!DOCTYPE html>
    <html>
    <body>
    <script>
     function timeToCall() {
            var calltime = document.getElementsByName("timetocall");
            for (var x = 0; x < calltime.length; x++) {
                if (calltime[x].checked == true) {
                    producePrompt("you have selected an appropriate time ", "timePrompt", "black");  
                    return true;
                } 
     }
     producePrompt("Please select an appropriate time for us to contact you", "timePrompt", "red");
            return false;       
        }
     function producePrompt(message, promptLocation, color) {
            document.getElementById(promptLocation).innerHTML = message;
            document.getElementById(promptLocation).style.color = color;
        }   
    </script>
    <form onsubmit="timeToCall();return false">
     <label for="nopref" id="no_pref">No Prefference</label><input type="radio" name="timetocall" id="nopref" value="nopref" />
     <label for="morning" id="morn">Morning(8-12)</label><input type="radio" name="timetocall" id="morning" value="morning" />          
     <label for="afternoon" id="after">Afternoon(12-4)</label><input type="radio" name="timetocall" id="afternoon" value="afternoon"  />            
     <label for="evening" id="eve">Evening(4-8)</label><input type="radio" name="timetocall" id="evening" value="evening"  />
     <br>
    <button type="submit">submit</button>
    <button type="reset">clear</button>
    </form>
    <span id="timePrompt"></span>
    </body>
    </html>
    Trying out your code in
    smaller units like the above
    is a good way to develop.
    Last edited by DaveyErwin; 01-01-2014 at 12:05 AM.


  •  

    Posting Permissions

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