Click to See Complete Forum and Search --> : Validation of text length does not seem to work


Nimisha
06-13-2003, 07:08 AM
Hi

The code below is to alert the user if the length of the text the user enters increases let say 10 characters. This code I have placed in the include file. At the mo nothing happens if I enetr more than 10 characters.

function ValidateField(OInput)
{

if(oInput.value.length>10)
{

alert("No way");
return false;
}

return true;

}
Response.Write "<INPUT type=text size=20 name=Keyword value=""" <input type=""submit"" onclick=""return checkinvalids(); ValidateField(Keyword);"" id=""btnSearch"" name=""btnSearch"" value=""" Test""">"

Any help/ideas much appreciated
Ta
Nimisha

Charles
06-13-2003, 07:14 AM
<input type="text" onchange="if (this.value.length > 10) {alert('Please limit yourself to ten characters.'); this.value=''; this.focus()}">

Lucky Punch
06-13-2003, 07:17 AM
maybe its this: you typed OInput/oInput in two differen ways.

Lucky

Khalid Ali
06-13-2003, 07:42 AM
Originally posted by Nimisha
onclick=""return checkinvalids(); ValidateField(Keyword);""
Nimisha

First of all..you have to remember that JavaScript is case sensitive..now in your

ValidateField(OInput)

function you are passing a parameter with capital "O" while in your comparission you are using small "o" the if statement must look like this

if(OInput.value.length>10)


Second..

in your html code for the onclick event you have 2 functions...if the first one has a problem the second one will ne be executed.
On top of that you have double "double" qoutes around the methods
This line
onclick=""return checkinvalids(); ValidateField(Keyword);""

should be
onclick="return checkinvalids(); ValidateField(Keyword);"

Thirdly you are passing form field to the ValidateField function by name to do that being on safe side use "this" keyword like this
ValidateField(this);

or

ValidateField(this.form.Keyword);

once all these are taken care of JavaScript is pretty straight forward..:D

Nimisha
06-13-2003, 08:04 AM
Hi Khalid

Thanx for the detailed reply, unfortunately lady luck is not shining on me. This is v frustrating cos it so straightforward.
My syntax again
function ValidateField(oInput)
{
if(oInput.length>1)
{
alert("Test");
return false;
}
return true;

}

Response.Write "<INPUT type=text size=20 id=Keyword name=Keyword value=""" &nbsp;<input type=""submit"" onclick=""return checkinvalids(); ValidateField(this); "" id=""btnSearch"" name=""btnSearch"" value=""" >

The double quote needs to be there else it gives me an error Expected end of statement.

Ta guys

Hope someone can help me out. :( This can't be happening ona Friday

Khalid Ali
06-13-2003, 08:56 AM
Originally posted by Nimisha
( This can't be happening ona Friday

We will not let this happen to your friday..:D :D

Now you seem to be using asp???

you will have to make sure that you are using correct syntax for concatenation fo the strings.

for javascript double qoutes are bad..bad..bad thing.

try something like this

Response.Write "<INPUT type=text size=20 id=Keyword name=Keyword value=\"\"> <input type=\"submit\" onclick=\"return checkinvalids(); ValidateField(this);\" id=\"btnSearch\" name=\"btnSearch\" value=\"\">"

Nimisha
06-13-2003, 09:11 AM
Hi Khalid

Looks like it going to be a long day.
Yes I'm using asp and this function sits on an include file.
The code works fine for the function checkinvalids, so i guess the problem has nothing to do with quotes etc. Can onsubmit have 2 functions being paased to it? I v new to Jscript, hence maybe a daft ques!
The ValidField function also seems to look correct, so I guess it may not be being called at all... is that so?

Is it Friday the 13th?

Nimisha

Khalid Ali
06-13-2003, 09:14 AM
you have a link to your page?...
or post code for the other function as well

Khalid Ali
06-13-2003, 09:36 AM
Oh cripes...
your condition is wrong..

f(oInput.length>1)
{
alert("Test");
return false;
}
return true;


should be

f(oInput.value.length<1)
{
alert("Test");
return false;
}
return true;


I am hoping that you are testing the text field for being empty...

Nimisha
06-17-2003, 01:09 AM
HI guys

Its been a long weekend here in a SA, hence the delay in reply.
It is definitley the fact that 2 function are bein called in the onclick routine that seems to be the problem. Is there any other way to call more than 1 function.
Ta
Nimisha

Nimisha
06-17-2003, 06:04 AM
Hi guys

Ta for all the replies. I got the problem sorted . To call more than 1 function you need to place "&&"between the functions i.e.<input type="button" onClick="function()&&function2()&&function3();">

Do appreciate the responses.
Nimisha:)