Wednesday 6 January 2016

enable and disable while loop textbox and checkbox using javascript

<?php
$i=1;
while($i<6){ ?><form action="" name="formname_<?php  echo $i ?>" method="post">
<div>
<label for='name'>Name<span class='required'>(required)</span></label>
<input type='text' id='textname_<?php echo  $i ?>' disabled="disabled"  placeholder='your name here' required value='<?php echo $i ?>'/>
</div>
<script>
function codename_<?php echo $i ?>() {

if(document.formname_<?php echo $i ?>.checkboxname_<?php echo  $i ?>.checked)
{
document.formname_<?php echo $i ?>.textname_<?php echo $i ?>.disabled=false;
}
else
{
document.formname_<?php echo $i ?>.textname_<?php echo $i ?>.disabled=true;
}
}</script>
<div style="width:70px; margin: 0 auto;">
<span >Edit</span> <input type="checkbox"   name="checkboxname_<?php echo  $i ?>"    onClick="codename_<?php echo $i ?>();" ></div>
</form><?php $i++; } ?>