The most trustable way of blurring/disabling elements

  • Thread starter Perttu Pulkkinen
  • Start date
P

Perttu Pulkkinen

What si the best and MOST BROWSERCOMPATIBLE way of making elements disabled
for the user? Also considering different kind of elements: textfields,
selects, radiobuttons and textareas. This is what I have had, its quite okay
in IE but not good enough for Netscape.

- I remember there was problem with setAttribute(wich would looked natural
pair to removeAttribute) so I used disabled = "disabled" instead.


function bluron(form,ele)
{
document.forms[form].elements[ele].style.backgroundColor = "silver";
document.forms[form].elements[ele].blur();
if(document.forms[form].elements[ele].getAttribute("disabled") == false )
{ document.forms[form].elements[ele].disabled = "disabled" }

}
// ***********************************************
function bluroff(ele)
{
if(document.forms[form].elements[ele].getAttribute("disabled") != false )
{ document.forms[form].elements[ele].removeAttribute("disabled") }
document.forms[form].elements[ele].style.backgroundColor = "white";
document.forms[form].elements[ele].focus();
}
 
P

Perttu Pulkkinen

What I found with google was something similar to this:

function enable()
{ document.myform.myelement.disabled = false }
function disable()
{ document.myform.myelement.disabled = true}

Now that is lousy function interface. It should be SOMETHING like this:

function enable(myform, myele)
{ document.myform.myelement.disabled = false }
function disable(myform, myele)
{ document.myform.myelement.disabled = true}

but this is not right, I think variables cannot be just put there? At least
with something like this i get error
"document.myform.myele has no properties. What I actually tried was:

function bluron(ele)
{ document.form.ele.disabled= true}
function bluroff(ele)
{ document.form.ele.disabled= false}

because I couldn't change the interface from what I had earlier. I hope
"form" as a word is not reserved in javascript namespace, because that is
the name of all my forms (how creative).

So what is right solution?
 
P

Perttu Pulkkinen

Duncan Booth said:
ele.disabled= true
}
function bluroff(ele) {
ele.disabled= false
}
If you already have the element you want to change, then the document and
form are irrelevant.

I have already answer but You mix object reference and object name. Or in a
way i mixed them when i used word "ele" wich sounds more like object
reference but was a name. But also your approach is okay, but different.
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top