vendredi 27 février 2015

Enable and disable textbox if checkbox is checked

I read this article as suggested by an answer for a similar question. I did everything the article said, but the end result wasn't what I wanted.


I want the text box to be disabled by default. When the checkbox is checked, the textbox is enabled.


What happened was that the textbox is enabled by default, and when the checkbox is checked, the textbox is disabled.


Here is my code:



<td class="trow2">
{$prefixselect}<input type="text" class="textbox" name="subject" size="40" maxlength="85" value="{$subject}" tabindex="1" />
<input type="checkbox" class="input_control" value="subject" />
<strong>I believe {$forum['name']} is the best section for this topic.</strong>
</td>

<script type="text/javascript">
$(document).ready(function(){
$('.input_control').attr('checked', true);
$('.input_control').click(function(){
if($('input[name='+ $(this).attr('value')+']').attr('disabled') == false) {
$('input[name='+ $(this).attr('value')+']').attr('disabled', true);
}
else {
$('input[name='+ $(this).attr('value')+']').attr('disabled', false);
}
});
});
</script>




Aucun commentaire:

Enregistrer un commentaire