|
-
Jul 30th, 2011, 04:10 AM
#1
Thread Starter
Hyperactive Member
[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..
-
Jul 30th, 2011, 09:35 AM
#2
Thread Starter
Hyperactive Member
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>
-
Jul 31st, 2011, 06:36 AM
#3
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,...
-
Jul 31st, 2011, 06:44 AM
#4
Thread Starter
Hyperactive Member
Re: [RESOLVED] checkboxes [javaScript]
 Originally Posted by akhileshbc
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|