Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Problem changing <input> background
Old 04-19-2008, 07:22 PM Problem changing <input> background
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
I cant think why? It works with the first text field, but not with the second! They use the same script and almost identical event handlers!

Here is my HTML
Code:
    <form action="" method="post" name="form1" class="contact" id="form1">
        <p class="frmIntro">Feel free to message us through  our contact form and we'll get back to you as soon as possible.</p>
  <p>
          <label for="name">Name</label>
          <input name="name" type="text" id="name" size="30" maxlength="30" onfocus="active(name)" onblur="deActive(name)" />
        </p>
        <p>
          <label for="email">E-mail</label>
          <input name="email" type="text" id="email" size="30" maxlength="100" onfocus="active(email)" onblur="deActive(email)" />
      </p>

Here is my javascript
Code:
// makes a text field turn white on focus
function active(field)
    {
        var field = document.getElementById(field);
        field.style.backgroundColor="#FFF";
    }
    
// makes a text field turn light grey on blur
function deActive(field)
    {
        var field = document.getElementById(field);
        field.style.backgroundColor="#F2F2F2";
    }
When clicking on 'email', it doesnt change colour. 'name' works perfectly though?

Also, the error message that comes up in Firefox is 'field has no properties'

Any ideas whats wrong? Thanks
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 04-19-2008, 08:02 PM Re: Problem changing <input> background
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Strings should be quoted, remember. I'm not sure why the name would work and not the email, but just try quoting the ID's you pass.

onfocus="active('email');"
onblur="deActive('email');"
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-20-2008, 06:02 AM Re: Problem changing <input> background
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Ahhh thanks thats fixed it! I have no idea why the name box was working properly though without the quotes?? Maybe because it was the first one in the form or something??

I ALWAYS get confused whether to pass quotes or not!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 04-20-2008, 06:36 PM Re: Problem changing <input> background
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Not sure why the name worked. If you really want to know, try just alert(name) or something and see what the value is The only thing I can think of is if you had some other JS on the page that set a 'name' variable.

As for quotes, just remember that ALL strings must be quoted. There's no exception to the rule. If they aren't quoted then JS will think it's a variable. (And if the variable doesn't exist, then it will be undefined, which is why the code errored out).
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem changing <input> background
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13199 seconds with 12 queries