Hi Guyz am having a problem in script.
Here goes the script
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language=javascript>
function BookingDetailsFin()
{
alert("saurav");
var tn = "1010243/cr";
int f=0;
var temp = null;
var temp1 = null;
var tasknumber = tn.value;
var tasknolength = tasknumber.length;
alert("Length is "+tasknumber.length);
temp = tasknumber.substring(0,7);
temp1= tasknumber.substring(7,10);
//var last = name.substring(len-3,len);
if(tasknumber == "")
{
alert("Please enter the Task Number");
//tn.page_taskno.focus();
//return false;
}
for(int i=0; i<temp.length; i++)
{
if(temp[i] >= '0' && temp[i] <= '9')
{
f++;
}
}
for(int i=0; i<temp.length; i++)
{
if((chr[i] >= 'A' && chr[i] <= 'Z') || (chr[i] >= 'a' && chr[i] <= 'z'))
{
f++;
}
}
if(!(f>0))
{
alert("please enter the alpha numeric vals");
}
else
{
var last2 = "/DR";
var last3 = "/CR";
if (temp1 == last2 || temp1 == last3)
{
alert("the string is equal");
}
else
{
alert("Enter proper value");
//tn.page_taskno.focus();
//return false;
}
}
}
/*function BookingDetailsFin()
{
alert("saurav");
}*/
</script>
</HEAD>
<BODY>
<input type ="button" name="aa" value="aa" onClick="javascript:BookingDetailsFin()" >
</BODY>
</HTML>
Clicking on the button isnt taking me to the desired func.......the func which i have written above.
but when i tried with one simple func which i had commented it was showing me the alert message.Guyz please help me out here.
Thanks in advance.
Saurav
var tn = "1010243/cr";
var temp = null;
var temp1 = null;
var tasknumber = tn.value;??
tn is variable. It value is a string. A string does not support value attribute (it will return undefined)
What tn suppose to be? An element with name ='1010243/cr'? If so, there are 2 mistakes. name and id should start only with a letter or underscore, not with a number. And the elements must be an object, not a string
var tn = document['formname']['elementname']
But looking at your commented:
//tn.page_taskno.focus()
tn looks rather like the form, but a form has no value... Is this a kind of validation code, or what?
saurav
03-16-2006, 03:41 PM
Thanks Kor for your reply.
Actually this script is a part of a big jsp,where you are right that is an object.
I was actually trying to do the draft in just a simple html page.
ok, so? Is there any other problem?