Thread: Javascript Help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    12
    Rep Power
    0

    Javascript Help


    Can anyone help me out with a bit of javascript?

    I have a number of tick boxs for, if the user doesn't select anything then all fields are searched.

    However the user can select to search specific fields, up to 15 in total.

    If the user clicks on specific boxes I want the all field to become unchecked.

    Any ideas how to do this?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2003
    Location
    Italy, EU
    Posts
    517
    Rep Power
    12
    I've tried this and seems to work:
    Code:
    <script type="text/javascript">
    <!--
    function chkAll(tick)
    {
    if(tick.name == "srcAll" && tick.checked)
    	{
    	for(var i=0; i < document.myForm.cbox.length; i++)
    		{
    		if(document.myForm.cbox[i].checked)
    			{
    			document.myForm.cbox[i].click();
    			}
    		}
    	}
    else
    {
    	if(tick.checked && document.myForm.srcAll.checked) document.myForm.srcAll.click();
    }
    }
    -->
    </script>
    
    
    <form name="myForm">
    <input name="cbox" type="checkbox" value="value1" onClick="javascript:chkAll(this)">Search one<br>
    <input name="cbox" type="checkbox" value="value2" onClick="javascript:chkAll(this)">Search two<br>
    <input name="cbox" type="checkbox" value="value3" onClick="javascript:chkAll(this)">Search three<br>
    <input name="cbox" type="checkbox" value="value4" onClick="javascript:chkAll(this)">Search four<br>
    <input name="srcAll" type="checkbox" value="1" checked="checked" onClick="javascript:chkAll(this)">Search ALL<br> 
    <input type="submit" value="Submit">
    </form>
    Cheers, Dave

IMN logo majestic logo threadwatch logo seochat tools logo