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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable form elements (cross browser) 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Does anyone know how to do a conditional on a form element which may lead to disabling it which will work in IE, NS and Opera? I've tried capturing the onKeyUp event for a text box, which runs a bit of script to disable another textbox (document.formname.textboxname.disabled=true), and I've tried using the onFocus event which runs a bit of script which blurs the textbox if the other textbox has some text in it.
 
Doing the conditional thing to disable one is pretty rough cross-browser.

Something we implemented here the other day was actually hiding a text box conditionally... and that you can do cross-browser.

document.formName.elementName.style.visibility='hidden';

or conversely,

document.formName.elementName.style.visibility='visible';

And you can even add a bit of code to wipe a box's contents before it's actually hidden so that if they've already typed something in there, it will get removed so your receiving page doesn't get confused. The reason you'd need to do that is that the text box would retain any value that had already been typed into it, even though it was hidden.

:)
Paul Prewett
penny.gif
penny.gif
 
hiee!

u can also do it usin focus/blur,

try this:

<script>
function disble(){ document.forms.myform.needed.onfocus=blurit }

function enble(){ 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=&quot;post&quot; action=&quot;&quot;>
<input type=textbox id='needed' name='needed' onfocus=''>
<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'>
</form>
 
I already tried the focus/blur method, which does work (but not in opera) but has a problem in netscape -> 'tabbing' from one element to another does not trigger the onFocus event, which leads to weird problems.
 
i dont understand what do u mean, but my functions wotk in netscate as well - check it yourself (i checked in nn4.5)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top