im sorry for this question but how can i disable a textbox if another textbox have a value??
I already try this code but its not working,, sorry for the noob question T_T
function disable(downpayment,full_payment)
{
if ( downpayment.value.length >= 1 )
document.getElementById(full_payment).disabled = true;
else
document.getElementById(full_payment).disabled = false;
}
</script>
<input name="downpayment" id="downpayment" type="text" onselect="function disable(downpayment,full_payment);" style="width:250px" />
</p>
<p>
<input name="full_payment" id="full_payment" type="text" style="width:250px" />
If you want to stay with plain JavaScript:
This works with the following HTML:
JS Fiddle demo.
If you’re using jQuery already, then you can either nest the above into jQuery’s
$(document).ready(function(){ /* the code in here */});, or switch to a jQuery-only solution, such as Alex’s.To stick with plain-JavaScript, and avoiding explaining how to set up an equivalent DOM-ready event, put the following at the end of your HTML content, just before the closing
</body>tag:(This is exactly the same JavaScript as above, with the comments stripped out, but wrapped in
<script></script>tags)Putting this at the bottom of the HTML means that the elements exist in the DOM prior to your trying to assign event-handlers to them.
Incidentally, with adjusted HTML, to give:
The following jQuery could be used:
JS Fiddle demo.