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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.