/    Sign up×
Community /Pin to ProfileBookmark

null and undefined

Okay, so I can define a variable to have it post the info in a popup from the page using

var Email= document.getElementById(‘Email’);

OR

var Email= document.Email.value;

But if there isn’t anything typed in that text box then it sets the box to read ‘null’ or ‘undefined’ respectivly.

Any way to keep the textbox empty if its value is null? When it sets it then the confirmation is thrown off cause there’s something in the box.

Thanks!

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliSep 16.2008 — Okay, so I can define a variable to have it post the info in a popup from the page using

var Email= document.getElementById('Email');

OR

var Email= document.Email.value;

But if there isn't anything typed in that text box then it sets the box to read 'null' or 'undefined' respectivly.

Any way to keep the textbox empty if its value is null? When it sets it then the confirmation is thrown off cause there's something in the box.

Thanks![/QUOTE]


If 'Email' is the ID of a text field:[CODE]var Email= document.getElementById('Email').value || "";[/CODE]
Copy linkTweet thisAlerts:
@kezzraauthorSep 17.2008 — Yes, 'Email' is the ID of the text field. Thanks for that, I tried it but its showing 'undefined' now rather than 'null'... I don't know if that might be because of later code or not so here's the whole thing.

Thanks again!

var called=false;

var Email= document.getElementById('email').value || "";

function compute(form){

called=true;

form.Email.value=" "+ Email;

}
Copy linkTweet thisAlerts:
@felgallSep 17.2008 — var Email= document.getElementById('email').value || null;
Copy linkTweet thisAlerts:
@kezzraauthorSep 17.2008 — That doesn't seem to be making a difference either. I'm thinking it might have something to do with the second part of it though now. Since the compute(form) fills in some of the other boxes. Those are based on select boxes though so just having trouble with the text boxes. Meh.
Copy linkTweet thisAlerts:
@felgallSep 17.2008 — It might have to do with the fact that a variable is normally only null if the variable doesn't yet exist. If the variable exists and hasn't been assigned a value yet then it has a value of undefined.
Copy linkTweet thisAlerts:
@DokSep 17.2008 — JS is case sensitive. If the id is 'Email' then referencing if must be
[CODE]document.getElementById('[COLOR="Red"]E[/COLOR]mail').value[/CODE]
and not
[CODE]document.getElementById('[COLOR="Red"]e[/COLOR]mail').value[/CODE]
Is the document fully loaded when accessing the input element? Change you code to start from the onload event of the body tag.
Copy linkTweet thisAlerts:
@kezzraauthorSep 17.2008 — The id is not capitalized. Correct. And compute(form) is run onload, so that's when its filling it it. I just need to be able to pull the info from the text box so I can have it show on a popup window, whether its blank or not.
Copy linkTweet thisAlerts:
@SingletonSep 18.2008 — It might have to do with the fact that a variable is normally only null if the variable doesn't yet exist. If the variable exists and hasn't been assigned a value yet then it has a value of undefined.[/QUOTE]

What a load of ****.
Copy linkTweet thisAlerts:
@DokSep 18.2008 — What a load of ****.[/QUOTE]
Wauw...your 4th post...and such eloquence already. I'm impressed.
×

Success!

Help @kezzra spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...