473,656 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onFocus in CSS?

56 New Member
Is it possible to have a textbox's focus using css? The background color should change when the cursor is in the active form field if possible, moving back to its original colour when another field is clicked.

At the moment I have this in <style>:
Expand|Select|Wrap|Line Numbers
  1. <style type=text/css>
  2.  
  3. p {font-family: verdana, arial, sans-serif; font-size: 10px;}
  4.  
  5. p.mySize {font-family: verdana, arial, sans-serif; font-size: 0.75em;}
  6.  
  7. table.myTable {margin-left:60px;}
  8.  
  9. input.blue {background-color: #D9F5F1; font-size: 12px; color: 1E1CDE;}
  10. input.marine {background-color: #D9F5F1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
  11. textarea.marine {background-color: #D9F5F1; font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;}
  12.  
  13. </style>
while the form itself, which is in a table, looks like this:

Expand|Select|Wrap|Line Numbers
  1. <table border="0" cellspacing="1">
  2.         <tr>
  3.             <td valign="top">
  4.                 <p class="mySize">Name:</p>
  5.             </td>
  6.             <td colspan="2">
  7.                 <input class="marine" name="ContactUs_Name" size="35" value="<% =ContactUs_Name %>">
  8.             </td>
  9.         </tr>
  10.         <tr>
  11.             <td valign="top">
  12.                 <p class=mySize>Email:</p>
  13.             </td>
  14.             <td colspan="2">
  15.                 <input class="marine" name="ContactUs_Email" size="35" value="<% =ContactUs_Email %>">
  16.             </td>
  17.         </tr>
  18.         <tr>
  19.             <td valign="top">
  20.                 <p class="mySize">Subject:</p>
  21.             </td>
  22.             <td colspan="2">
  23.                 <input class="marine" name="ContactUs_Subject" value="<% =ContactUs_Subject %>" size="35">
  24.             </td>
  25.         </tr>
  26.         <tr>
  27.             <td valign="top">
  28.                 <p class="mySize">Message:</p>
  29.             </td>
  30.             <td valign="top">
  31.                 <textarea class="marine" rows="10" name="ContactUs_Body" cols="35"><% =ContactUs_Body %></textarea>
  32.             </td>
  33.         </tr>
  34.         <tr>
  35.             <td valign="top">
  36.                 &nbsp;
  37.             </td>
  38.             <td colspan="2">
  39.                 <input class="blue" type="submit" value="Send">
  40.             </td>
  41.         </tr>
  42.     </table>
Many thanks.
Apr 26 '12 #1
2 2483
Rabbit
12,516 Recognized Expert Moderator MVP
You can use the :focus selector. For it to work in IE8, a DOCTYPE has to be declared.
Apr 26 '12 #2
Bluenose
56 New Member
Hello Rabbit

Many thanks for that - I will read up on it.

Cheers
Apr 26 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7267
by: Mike Berger | last post by:
So, I'm fairly new to this and my code is as follows... <script language="JavaScript> var oldValue function focusElement(theElement) { oldValue = theElement.value; return; } </script>
1
20268
by: Rich Morey | last post by:
Hello, I have created a form and assigned each of the form elements to a class in a style sheet. I would like to know if it is possible to add 'OnFocus' and 'OnBlur' events to the style sheet class so that I can change the background color of a form element WITHOUT having to add 'OnFocus' and 'OnBlur' events to each individual form element..
1
8746
by: Michael Albanese | last post by:
I am developing an application to handle my compay's OSHA reporting requirements. Some of the input criteria are technical and narowly defined, so I was trying to prvide what i call "Context Sensitive Help" by providing a short instructional message based on which control has Focus. Because of the way that a Radio Button List control is rendered in the browser i can not attach an onFocus event
2
3130
by: Paresh Shah | last post by:
Hi Friends... I have an query on how to capture onFocus event for all the input controls without writing onFocus event in the <input> tag. say my html form has 3 or 4 or 5 input text boxes, now I want to capture onFocus event for all the text boxes without writing onFocus code in <input> tag.
2
3983
by: swathi | last post by:
----------------------------------------------------------------------- A poll associated with this post was created, to vote and see th results, please visit http://www.forum4designers.com/message103437.htm ----------------------------------------------------------------------- Question: iframe onfocus problem in mozilla browse - attached zip fil - multi.html in attached zi...
1
10485
by: Tzachi | last post by:
Hello all, I have a function that dynamically adds rows and columns to the page. Everything works well except onfocus // onblur attributes. For some reason, when entering the input box it doesn't highlight. If I delete the onblur line, each of the boxes is highlighted all the time regardless of focusing the input box. Can someone help me?
1
2380
by: Eric Trav | last post by:
Hello, I am using mozilla and javascript to change the style background color for my select with onfocus() and back to white with onblur(). When i process onfocus(); i have to click on the select three times to get the popup menu and everything seems slow. No errors are reported in the console however it seems as if the click event is not being processed after the focus event is processed.
1
1927
by: clemtig | last post by:
Say I have a form with two input textfields. Each has an onFocus and onBlur. onFocus will unhide image #1. onBlur will hide image #1, show image #2 and validate the textfield. But the problem is that I get errors when going from one field to another with this combination. I've got it down to the point where I know that going from input field 1: onBlur --to-- input field 2: onBlur + onFocus
4
3918
by: spree | last post by:
Hi, I have a coloumn of buttons where i would like to highlight it when focussed... So, i have used onFocus element for it. Till here its ok. But if i set any background color for the button and then use the onFocus element, its not getting focussed that is its not showing as focussed.So,could anybody help me to find out solution for this. And also tell me how to change the default color of onFocus element to any desired color.
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8498
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.