Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ticking a checkbox changes the value of a field in a form

Status
Not open for further replies.

arobbo

IS-IT--Management
Feb 15, 2005
62
GB
hi , afraid my javascript is quite basic (when i was at uni many years ago it appears i didn't pay enough attention )

i'm trying to do something very simple but getting no where fast ...

basically if a check box is ticked i want it to change the value to 0.5 and if it is unticked to run a function ... so far my code looks like this



<script language="javascript">

function checkBox() {

if (document.form.halfDay.checked) {
(document.form.lenghtOfAbsence.value)=="0.5";
}

}

</script>

which is initiated by the following in the form


<input type =checkbox name = halfDay onChange="checkBox()">

can anyone help me please
 
Change your onChange event to an onClick event and, in your function, change (document.form.lenghtOfAbsence.value)=="0.5"; to (document.form.lenghtOfAbsence.value)[highlight]=[/highlight]"0.5";.

The double-equals sign (==) is to compare for equality. The singal equals sign (=) is for assignment of values.

'hope that helps.

--Dave
 
you little beauty

much appreciated ;)
 
Ooh! Always nice to get a compliment! I'll annoy my officemates by whistling the rest of the morning! :)

Have a great day!

--Dave
 
arobbo
This line: (document.form.lenghtOfAbsence.value)=="0.5";
is comparing the value of that field not setting it.
== is for comparing like: if (this == that).
= is for assigment like: this = that;

Try your function like this:
function checkBox() {

if (document.form.halfDay.checked) {
document.form.lenghtOfAbsence.value = "0.5";
}
else
someotherfunction();
}


Paranoid? ME?? WHO WANTS TO KNOW????
 
Damn, did it again. Stop to answer WORK related questions and my post goes in late. :)


Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top