Results 1 to 4 of 4

Thread: [RESOLVED] checkboxes [javaScript]

  1. #1

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Resolved [RESOLVED] checkboxes [javaScript]

    hi,
    here's code for radio buttons i'm doing for checking gender, can anyone tell me how can i do this using checkboxes?
    Code:
    <html>
    <head>
    <title>Task</title>
    <script>
    	function check()
    	{
    		if(document.task.gender[0].checked || document.task.gender[1].checked)
    		{
    			alert("ok, checked");
    		}
    		else if(!document.task.gender[0].checked && !document.task.gender[1].checked)
    		{
    			alert("u must check one");
    		}
    	}
    </script>
    </head>
    <form name=task id="task">
    <table>
    <tr>
    	<td><input type='radio' name=gender value='male'></td>
    	<td>male</td>
    </tr>
    <tr>
    	<td><input type='radio' name=gender value='female'></td>
    	<td>female</td>
    </tr>
    <tr>	
    	<td><input type='button' value='click' onClick="check()"></td>
    </tr>
    </table>
    </form>
    </html>
    thanks..

  2. #2

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: checkboxes [javaScript]

    Anyways, i've done this. I wanted to do this..
    Code:
    <html>
    <head>
    <title>Task</title>
    <script>
    	function check()
    	{
    		if(document.task.gender[0].checked) 
    		{
    			document.task.gender[1].checked=false;
    		}
    		else if(document.task.gender[1].checked)
    		{
    			document.task.gender[0].checked=false;
    		}	
    	}
    </script>
    </head>
    <form name=task id="task">
    <table>
    <tr>
    	<td><input type='checkbox' name=gender value='male' onClick='check()' checked></td>
    	<td>male</td>
    </tr>
    <tr>
    	<td><input type='checkbox' name=gender value='female' onClick='check()'></td>
    	<td>female</td>
    </tr>
    </table>
    </form>
    </html>

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] checkboxes [javaScript]

    Radio buttons are meant for selecting a single item from a group whereas checkboxes are for selecting multiple items !

    So, radio buttons are more apt for "Gender" and checkboxes can be used in cases like "Languages known:".


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: [RESOLVED] checkboxes [javaScript]

    Quote Originally Posted by akhileshbc View Post
    Radio buttons are meant for selecting a single item from a group whereas checkboxes are for selecting multiple items !

    So, radio buttons are more apt for "Gender" and checkboxes can be used in cases like "Languages known:".

    ok

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