473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

textarea with value "" undefined?

Hello,

I have a form with an input field, a textarea, having a value of ""
Also, I have some javascript code, which may be reduced to the following:

function validate(mycode)
{
alert(mycode.value == undefined);
}

validate(myForm.field);

where 'field' is the field I am talking about, the one that looks like this:

<INPUT TYPE=text NAME=field VALUE="" MAXLENGTH=4 SIZE=4>

My alert shows up as true.

Can someone please explain why, or point me where to look?

thank you very much,

denis

Jul 23 '05 #1
2 3482
Denis Perelyubskiy wrote on 17 okt 2004 in comp.lang.javascript:
function validate(mycode)
{
alert(mycode.value == undefined);
}

validate(myForm.field);

where 'field' is the field I am talking about, the one that looks like
this:

<INPUT TYPE=text NAME=field VALUE="" MAXLENGTH=4 SIZE=4>


alert(myForm.field.value == "");
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
Denis Perelyubskiy wrote:
[snip]
Can someone please explain why, or point me where to look?


The alert will evaluate what is inside the brackets and put the result
in the alert box. Your test asks "is the value of the text box
undefined?" and the answer is no, or "false". I don't know why you are
getting true, you must have an error in your code somewhere. Here is a
working snippet:

<script type="text/javascript">
function validate(mycode) {
alert(mycode.value == undefined);
}
</script>

<form action="" name="myForm">
<INPUT TYPE="text" NAME="field" VALUE="" MAXLENGTH="4" SIZE="4">
<input type="button" value="click"
onclick="validate(myForm.field)">
</form>

Your test asks if the element "field" has a value, and it does - either
an empty string or whatever has been typed in, so the test is always
"true". If you want to see if the string has a value, then use
Evertjan's solution.

As written, the alert returns "true" if the field is empty, or "false"
if it has something in it. To reverse the sense, use:

alert(!myForm.field.value == "");

and you will get false if it's empty and true if it isn't.

However, I'd presume that you need to do far more validation than
simply test that something has been added.

Rob.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: HD | last post by:
Hello, Here is my code... <table> <tr><td><strong>TERRITOIRES</strong></td></tr> <tr><td><input type="radio" name="terriprod" value="P" onClick="Javascript:alert('la valeur de terriprod...
14
by: TTroy | last post by:
Hello, can anyone explain why the following function will not work for INT_MIN: /* itoa: convert n to characters in s */ void itoa(int n, char s) { int i, sign; if((sign = n) < 0) /*...
3
by: Mark Sullivan | last post by:
When I trace through a csharp program I came to a situation where a certain values has an "undefined value" as shown in the debugger DbgClr. I want to check this but the following statements did...
12
by: Emi Lu | last post by:
Hello all, I have a question about "date" & "timestamp" types in PostgreSQL. I want to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for them. However, it seems that PostgreSQL...
1
by: OtisUsenet | last post by:
Hi, I have a bookmarklet that works perfectly in Firefox, IE, Konqueror, and Opera, but in Safari 2.0.3 (417.9.2) it doesn't work. I enabled debugging and I can see "TypeError - Undefined...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
1
by: mithunmo | last post by:
If I run the below program . I get the following error message Can't call method "value" on an undefined value at C:/Perl/site/lib/Win32/IE/Mec hanize.pm line 900. Please let me know your...
2
by: mithunmo | last post by:
I am trying to automate the process of filling up the webforms and do a submit . I have the below program written but If I run the program . I get the following error message Can't call method...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.