Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question problem in staying on same page or moving to next

    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

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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:
    Code:
    <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:
    Code:
    <form name="form1" action="whatever" onSubmit="return numbercheck1();">
    Last edited by Brandoe85; 10-23-2004 at 08:00 AM.

  • #3
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile thanks

    thanks buddy i works perfect

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You're welcome


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •