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
Why can't I figure this out?
Old 08-18-2009, 02:07 AM Why can't I figure this out?
Super Talker

Posts: 132
Trades: 0
Name is a text input field.
All I'm really trying to do is say:
if name's value is "name" then onfocus name's value is "".
BUT
if name's value is anything OTHER THAN "name", keep that value, don't change to "".

For some reason I can't translate that into javascript.. Maybe I'm tired?
Help!

Thanksss
Code:
var name = document.getElementById('nameQ');
    
    name.value = "name";
    
    if(name.value != "name") {
        return false;
    } else {
        name.onfocus = function() {
            name.value = "";
        }
    }
    name.onblur = function() {
        if(name.value == "") {
            name.value = "name";
        }
    }
soap is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-18-2009, 10:40 PM Re: Why can't I figure this out?
Super Talker

Posts: 132
Trades: 0
any takers?
soap is offline
Reply With Quote
View Public Profile
 
Old 08-19-2009, 12:33 AM Re: Why can't I figure this out?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
The problem is, you're setting name's value right at the beginning, so the
Code:
if(name.value != "name")
condition can never possibly happen.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 08-19-2009, 01:27 AM Re: Why can't I figure this out?
Super Talker

Posts: 132
Trades: 0
it should be so easy... whyyyyyyy
there's something obvious that i'm missing.

Code:
var name = document.getElementById('nameQ');

name.onfocus = function() {
        if(name.value = "name") {
            name.value = "";
        } else if (name.value != "name") {
            alert('hi');
        }
    }
doesn't even work...
soap is offline
Reply With Quote
View Public Profile
 
Old 08-19-2009, 08:51 PM Re: Why can't I figure this out?
dday76's Avatar
Novice Talker

Posts: 8
Name: JDT
Trades: 0
Try
if(name.value == "name") {

And it looks like you can ditch the elseif statement altogether.
dday76 is offline
Reply With Quote
View Public Profile Visit dday76's homepage!
 
Reply     « Reply to Why can't I figure this out?
 

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.42042 seconds with 12 queries