Solved

Locking or disabling a select object

Posted on 2000-03-23
3
193 Views
Last Modified: 2010-04-09
Is it possible? How can I do it?

Thanks in advance!

Teresa
0
Comment
Question by:MTF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 2649952
<SELECT onFocus='this.blur();'>
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 100 total points
ID: 2649962
This is overkill, but it will do what you want:


<HTML>
<HEAD>
<TITLE>Enabling/Disabling Fields in NetScape and IE</title>

<SCRIPT language='javascript'>
<!-- //


function disable_enable(form)
{
   form.myfield.disabled    = !form.myfield.disabled;
   form.myselect.disabled   = !form.myselect.disabled;
   form.mytextarea.disabled = !form.mytextarea.disabled;

   window.status = 'Setting disabled flags to: ' + form.myfield.disabled;
   form.mybutton.value = ( form.myfield.disabled ) ? "Disabled" : "Enabled";
}


function onFieldFocus(element)
{
   window.status = element.name + ' disabled flag is: ' + element.disabled;

   if ( element.disabled )
   {
      // you might be tempted to do this: element.blur();
      // but this may cause problems for earlier browsers.  Use setTimeout:
      setTimeout("document.myform." + element.name + ".blur()",1);
   }
}


function onPageLoad(form)
{
   // initialize disabled flags
   form.myfield.disabled    = false;
   form.myselect.disabled   = false;
   form.mytextarea.disabled = false;

   form.myfield.focus();
   form.myfield.select();

}

// -->
</script>
</head>

<BODY onLoad='onPageLoad(this.myform);'>
<FORM name='myform'>

 My Field: &nbsp;
 <INPUT type='text'   name='myfield'  value='kEk' width='12' maxlength='24'
        onFocus='onFieldFocus(this)'><BR>

 My Select:
 <SELECT name='myselect' disabled onFocus='onFieldFocus(this)'>
   <OPTION></option>
   <OPTION>opt 1</option>
   <OPTION>opt 2</option>
   <OPTION>opt 3</option>
 </select><BR>

 My Text Area:<BR>
 <TEXTAREA name='mytextarea' wrap rows='4' cols='32' onFocus='onFieldFocus(this)'>blah blah blah</textarea><P>

 <INPUT type='button' name='mybutton' value=' Enabled ' onClick='disable_enable(this.form);'>

 <P>
 <!-- to permanently disable a field, it is not so complicated: -->
 Always Disabled:  
 <INPUT type='text' name='myfield2' disabled value="I'm Disabled!" width='14' maxlength='24'
        onFocus='setTimeout("document.myform.myfield2.blur()",1)'><BR>

</form>

</body>
</html>

0
 

Author Comment

by:MTF
ID: 2650006
Thanks a lot!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question