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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer to Control with variable 1

Status
Not open for further replies.

Tinkerers

Technical User
Sep 26, 2002
90
US
Hi,

This should be an easy question for someone who understands Javascript. I have the following code:
<form name="form2">
<input type='checkbox' name='chk1' onclick="fct('1','Paul');">
<input type='text' name='Tech'">
</form>

<script>
function fct(cnt,user)
{
if (window.document.form2.chk+cnt+.checked==true)
{
document.form2.Tech.value=user;
}
}
</script>

I need to simply test whether the checkbox is checked. But there is a variable I pass in the onclick event, which passes the number of the checkbox. I can't figure out how to refer to this checkbox control. The above code will not work.
Thanks for any help,
Paul
 
>if (window.document.form2.chk+cnt+.checked==true)
[tt]if (window.document.form2.[blue]elements["chk"+cnt][/blue].checked==true)[/tt]
or simply
[tt]if (window.document.form2.[blue]elements["chk"+cnt][/blue].checked)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top