PDA

View Full Version : invert inputs - newbie help


bmcua
05-29-2003, 12:59 PM
I'm a newbie when it comes to javascript.
I need to invert all the checkbox when the user submit the form.
so far i got this


<script language="JavaScript" type="text/JavaScript">
<!--
function invert() {

in here......i am not sure how to invert

}
//-->
</script>


<form name="form" method="post" action="search.php">

<input type="checkbox" name="ethnic[]" value="0">
<input type="checkbox" name="ethnic[]" value="1">
<input type="checkbox" name="ethnic[]" value="2">
<input type="checkbox" name="ethnic[]" value="3">
<input type="checkbox" name="ethnic[]" value="4">

<input type="submit" name="Submit" value="Search" onClick="invert()">

</form>

please help me........

thanks

requestcode
05-29-2003, 01:14 PM
Not sure what you mean by "invert". Can you give us some more details?

bmcua
05-29-2003, 01:33 PM
basically i want all the boxes which are check to be unchecked, or the other way round.

for example

if(form.photo.checked = true)
form.photo.checked = false;

bmcua
05-29-2003, 02:36 PM
its ok.........got the answer.......yeppie!

// javascript here

// every checkbox that is checked unchecked it and vice versa
function invert() {

for(i=0; i<document.form1['ethnic[]'].length; i++) {
if(document.form1['ethnic[]'][i].checked)
document.form1['ethnic[]'][i].checked = false;
else
document.form1['ethnic[]'][i].checked = true;
}
}

// html here
<form name="form1" method="post" action="search.php" onSubmit="invert()">

<input type="checkbox" name="ethnic[]" value="1">
<input type="checkbox" name="ethnic[]" value="2">
<input type="checkbox" name="ethnic[]" value="3">
<input type="checkbox" name="ethnic[]" value="4">

<input type="submit" name="Submit" value="Search">

</form>

just need to try........... it should work......... =)