Current location: Hot Scripts Forums » General Web Coding » JavaScript » how to check == undefined ??


how to check == undefined ??

Reply
  #1 (permalink)  
Old 03-30-04, 04:58 PM
Puno Puno is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Spain (EU) Colorado (USofA)
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy how to check == undefined ??

Please, how would i check if some value is undefined?
like for example:

(document.form.textbox.value == undefined)

but correct sintax

Seems simple but i swear i have been for 3 horus at it...
thanks a lot in advance
Puno.
Reply With Quote
  #2 (permalink)  
Old 03-30-04, 06:01 PM
addit addit is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Null...

Try this: (document.form.textbox.value == null)
Reply With Quote
  #3 (permalink)  
Old 03-31-04, 01:20 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
checking for null will work since undefined==null

But in my scripts I have sometimes have no problems with checking for undefined using the first example. I don't know why but in some scripts it seems to work and in some it doesn't...

All I know for sure is that it always works when you are checking to see if an argument has been sent to a function or not, like this:

function Test(arg){
if(arg==undefined){
arg="default"
}
}
Reply With Quote
  #4 (permalink)  
Old 03-31-04, 12:31 PM
Puno Puno is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Spain (EU) Colorado (USofA)
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Replying to myself to make sure I dont confuse other people checking it out.

First of all, thanks everyone for the replies, they made me realize my mistake was not there and found where the problem was.

It was a noob mistake, in the hurry and stress I was trying to access a radiobutton's value directly like so:
document.form.radio.value
This is a big no no


Remember radio buttons are in a sense at least, ARRAYS
seems to be correct:
document.form.radio[index].value

And that can be compared to undefined or null.
Yup, I noticed that to simplify I used a textbox in my example, if I would have used the radiobutton you could have told me straight where my problem (idiocy) lied.

Well, thanks a lot for your help and hope this helps more people down the line. =)

Puno.
Spectrum 48K BASIC's was cooler, it had a BEEP instruction.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
email duplicate check jrave PHP 2 03-16-04 08:04 PM
PHP: check data transfer on certain directories? Agum PHP 7 12-30-03 03:58 AM
How to check mail() MCM PHP 2 08-14-03 06:41 AM
How can I check input field for float number entered? wh1te_zp JavaScript 0 08-13-03 08:48 AM


All times are GMT -5. The time now is 02:14 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.