...

View Full Version : problem in staying on same page or moving to next



talat
10-23-2004, 08:04 AM
hi friends
consider the senario for example if i am taking some input from user on my page and checking that the input should be a number for that imake a script shown below which is working fine

<script language="JavaScript">
function numbercheck1()
{
if (document.form1.text1.value=='')
{
alert('The box was empty. Please enter a number');
}
else
{
n=document.form1.text1.value.length;
for (i=0;i<n; i++)
{
cchar=document.form1.text1.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0'))
{

}
else
{
alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.text1.value='';
break;
}
}
}
}
</script>

and call it onclick event of submit button

<input type="submit" name="Submit" value="Submit" onclick="numbercheck1()">

now my problem is

"WHEN I CLICK SUBMIT BUTTON IF I GAVE WRONG ENTRY IN THE TEXTBOX MYSCRIPT SHOW ALERT BUT ALSO TAKE ME TO THE PAGE MENTION IN ACTION OF FORM "

whati want is that itshould keep me to the same page when the entry is wrong and kep cursor focus on the first textbox of page take me to new page when entry is write

plz help me how to do that

Brandoe85
10-23-2004, 08:29 AM
I think you posted this in the wrong forum, I don't think it should be in the DOM forum, but anways...change these lines:


<script language="JavaScript">
function numbercheck1()
{
if (document.form1.text1.value=='')
{
alert('The box was empty. Please enter a number');
document.form1.text1.focus();
return false;
}
else
{
n=document.form1.text1.value.length;
for (i=0;i<n; i++)
{
cchar=document.form1.text1.value.charAt(i);
if (parseFloat(cchar)|| (cchar=='.')||(cchar=='0'))
{

}
else
{
alert('The character \''+cchar+'\' is not a number\nPlease enter numbers only');
document.form1.text1.value='';
document.form1.text1.focus();
return false;
break;
}
}
}
}
</script>
<input type="submit" name="Submit" value="Submit" onclick="return numbercheck1()">

Also, what you could do is just have an onsubmit handler in the form tag:


<form name="form1" action="whatever" onSubmit="return numbercheck1();">

talat
10-23-2004, 09:31 AM
thanks buddy i works perfect

Brandoe85
10-23-2004, 09:46 AM
You're welcome :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum