Jump to content

show checkbox as check with dynamic values not working


zohab

Recommended Posts

hi all

 

i have created one check box and from a javascript function when i provide hard coded name for

checkbox then it shows check but in case of dynamic value it does not show check

 

checkbox in html

[code]<input type="checkbox" name="checkbox2" id="checkbox2" value="checkbox">

var i=2;
var check="checkbox"+i;
document.frmCheck.checkbox2.checked=true; // working
document.frmCheck.checkboxi.checked=true;	 // not working
document.frmCheck.checkbox+i.checked=true;	 // not working
document.frmCheck.check.checked=true;	 // not working

 

 

any ideas?

 

full code as below

pls try it

 

 

 

 

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post" name="frmCheck"><table width="100" border="1">
  <tr>
    <td>Check1</td>
    <td><input type="checkbox" name="checkbox1" id="checkbox1"  onClick="return test();"value="checkbox">
	<input type="hidden" name="value1" id="value1" value="1">
</td>
  </tr>
  <tr>
    <td>Check2</td>
    <td><input type="checkbox" name="checkbox2" id="checkbox2" value="checkbox">
	<input type="hidden" name="value2" id="value2" value="2">
</td>
  </tr>
  <tr>
    <td>Ckeck3</td>
    <td><input type="checkbox" name="checkbox3" id="checkbox3" value="checkbox">
	<input type="hidden" name="value3" id="value3" value="3">
</td>
  </tr>
  <tr>
    <td>Check4</td>
    <td><input type="checkbox" name="checkbox4" id="checkbox4" value="checkbox">
	<input type="hidden" name="value4" id="value4" value="4">
</td>
  </tr>
  <tr>
    <td>Field</td>
    <td><input type="text" name="textfield" id="textfield" value=""></td>
  </tr>
</table>
<script language="javascript" type="text/javascript">
		function test()
		{

				var value=document.frmCheck.value1.value;

				var i=2;
				var check="checkbox"+i;
				document.frmCheck.checkbox2.checked=true; // working
				//document.frmCheck.checkboxi.checked=true;	 // not working
				//document.frmCheck.checkbox+i.checked=true;	 // not working
				//document.frmCheck.check.checked=true;	 // not working



		}
	 test();
</script>
</form>


</body>
</html>

 

 

 

 

 

 

 

 

 

[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.