Results 1 to 8 of 8

Thread: form validation - radios

  1. #1
    sashabinkie
    Guest

    Unhappy

    can't figure out why the #&@ this doesn't work:

    if (!(frmMan.chkDis.checked))
    {
    alert("Please indicate a Discipline.");
    frmMan.chkDis(0).focus();
    return false;
    }
    else
    {
    return true;
    }

    Any help would be greatly appreciated!!

    whether the radios are selected or not it performs the if and not the else.

  2. #2
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294

    Lightbulb

    Code:
    if (frmMan.chkDis.checked) 
    { 
    return true; 
    } 
    else 
    {
    alert("Please indicate a Discipline."); 
    frmMan.chkDis(0).focus(); 
    return false; 
    }
    how about that?

  3. #3
    Guest

    Unhappy The old negative routine hunh!

    Tried inverting this, sama ting it always gives me the else now and not the if. Any other ideas?!!

  4. #4
    Guest

    Unhappy The old negative routine hunh!

    Kagey, thanks for the post I tried inverting this, sama ting it always gives me the else now and not the if. Any other ideas?!!

  5. #5
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    Is this a set of radio buttons, or a checkbox? if it is a set of radio buttons, try this for the if statement:
    Code:
    if (frmMan.chkDis.value = "") 
    { 
    return true; 
    } 
    else 
    {
    alert("Please indicate a Discipline."); 
    frmMan.chkDis(0).focus(); 
    return false; 
    }

  6. #6
    Guest

    reversed

    Kagey, thanks again I took your code and cut and pasted it results are the same it now performs the else no matter wether the radio button is checked or not. Inverting this gives me the same result it performs the if statement and never performs the else, thanks.

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    it's far from clear waht it is you are trying to do.
    Are you testing to make sure that at least one radio button id checked?
    If so, this might help:

    Code:
    <HTML>
    <HEAD>
    <script language=javascript>
    function doit()
    {
    var r 
    
    	for(i=0;i<=4;i++)
    	{
    		r |= document.frm1.radio1(i).checked
    	}
    	
    	if(r==0)
    	alert("Please indicate a Discipline."); 
    
    }
    
    </script>
    </HEAD>
    <BODY>
    <form name=frm1>
    <INPUT id=radio1 name=radio1 type=radio><BR>
    <INPUT id=radio1 name=radio1 type=radio><BR>
    <INPUT id=radio1 name=radio1 type=radio><BR>
    <INPUT id=radio1 name=radio1 type=radio><BR>
    <INPUT id=radio1 name=radio1 type=radio><BR>
    <input type=button onclick="doit()">
    </form>
    </BODY>
    </HTML>
    Mark
    -------------------

  8. #8
    Guest

    Thanks

    Thanks Mark!!!
    Looks like that is exactly what I needed, I went to cnet and found an article from Charity Kahn I redid her code at http://builder.cnet.com/Programming/Kahn/042298 and it got me squared away here thanks alot!!!!
    final code looked like this:

    function deptChecked(form) {
    for (i=0; i<form.chkDis.length; i++) {
    if (form.chkDis[i].checked) {
    return true;
    }
    }
    return false;
    }
    function validateForm(form)
    {
    if (frmMan.frmComment.value == "")
    {
    alert("Please give us your comments concerning this Lesson.");
    return false;
    }
    if (!deptChecked(form))
    {
    alert("Please indicate a Discipline.");
    return false;
    }
    else
    {
    return true;
    }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width