Hi !
try this line
if (curObj.checked)
instead of
if (document.myform.elements[curObj.name].checked==1 )
Oleg.
-----Original Message-----
From: speedguru@m... [mailto:speedguru@m...]
Sent: May 09, 2002 1:20 PM
To: javascript
Subject: [javascript] trouble with onClick event
hi,
thanks to oleg for replying to my prev question
i've got a form with checkboxes and txtboxes adjacent to them. whenever
the checkbx is chked i wish to set the value to 1 and set it to blank when
its unchecked.
i dont know where i'm going wrong with this piece of code and i need help.
first time when i check value of equivalent txtbox is set to 1 but the
next time the checked value is false (??????) and txtbox remains blank
<body onclick='klick()'>
<script language='jscript'>
function klick()
{
var curObj = window.event.srcElement;
//"INPUT" should be in capitals
if (curObj.tagName == "INPUT" && curObj.type == "checkbox")
{
tbox= "t" + curObj.name
//alert(tbox)
//alert('elname=' + document.myform.elements[curObj.name].value
+ "elchecked=" + document.myform.elements[curObj.name].checked )
if (document.myform.elements[curObj.name].checked==1 )
{
//alert(document.myform.elements[curObj.name].checked)
document.myform.elements[tbox].value=1
}
else
{
//alert(document.myform.elements[curObj.name].checked)
document.myform.elements[tbox].value=""
}
}
}
</script>
<form name="myform">
<input type='checkbox' name="1" value="c1val"><input type='text'
name='t1' ><br>
<input type='checkbox' name="2" value="c2c1val"><input type='text'
name='t2' ><br>
<input type='checkbox' name="3" value="c3c1val"><input type='text'
name='t3' ><br>
<input type='checkbox' name="4" value="c4c1val"><input type='text'
name='t4' ><br>
<input type='checkbox' name="5" value="c5c1val"><input
type='text'name='t5' ><br>
<input type='checkbox' name="6" value="c6c1val"><input type='text'
name='t6'><br>
<input type='checkbox' name="7" value="c7c1val"><input type='text'
name='t7'><br>
<input type='submit' >
</form>
</body>
thanks for your time
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20