Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disabling form elements

form elements

disabling form elements

by  baad  Posted    (Edited  )
simple code, workin in MSIE & Netscape (may be in others too - didnt checked myself)

this example is about textbox

<script>
function disble(){
document.forms.myform.needed.value='heh! locked'
document.forms.myform.needed.onfocus=blurit
}

function enble(){
document.forms.myform.needed.value='write whateva u want'
document.forms.myform.needed.onfocus=new Function() }

function blurit(){
//document.forms.myform.needed.blur()
//or
document.forms.myform.next.focus()
}
</script>

<form id='myform' name='myform' method="post" action="">
<input type=textbox id='needed' name='needed' onfocus=' value='write whateva u want'>
<input type=button value='click 2 make textbox uneditable' onmousedown='javascript:disble()'>
<input type=button value='click 2 make textbox editable' onmousedown='javascript:enble()'>
<input type=textbox name='next' value='just 2nd textbox (for 2nd method in blurit())'>
</form>

yeah, & iza asked me for a small addition:
this functions wuld work for almost all form elements, at least for textarea & select (dropdown), (except radio, checkbox & button i think)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top