Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

javascript problem

  • 07-08-2007 10:47am
    #1
    Registered Users Posts: 36


    trying to error check, to make sure its only numbers entered where they should be and only letter where there should be letters, nearly there i thing, so if anyone can spot the prob, thanks

    i have all the code here so just copy and paste the 2 files in the same folder and u will c exactly whats wrong,
    thanks again

    <!-- store2.asp -->

    <script language="javascript" type="text/javascript" >
    <!-- Begin
    //Form input validation routine.
    //The function is used to check that user input contains valid information
    //before it is passed to other program logic. The checkNumericForm() function
    //uses the chkNumeric() function to ensure that the each individual input field
    //contains valid information.
    function checkNumericForm(objName,minval, maxval,comma,period,hyphen, text)
    {
    if (chkNumeric(objName.PIN,1000,maxval,comma,period,hyphen, "no") == false)
    {
    objName.PIN.select();
    objName.PIN.focus();
    return false;
    }
    else if (chkNumeric(objName.UserName,minval,maxval,comma,period,hyphen, "yes") == false)
    {
    objName.UserName.select();
    objName.UserName.focus();
    return false;
    }
    else
    {
    return true;
    }
    }

    function chkNumeric(objName,minval,maxval,comma,period,hyphen, text)
    {

    if ( text == "yes" )
    {
    var textCheckOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var textCheckStr = objName;
    var textAllValid = true;
    var allText = "";

    for (i = 0; i < textCheckStr.value.length; i++)
    {
    ch = textCheckStr.value.charAt(i);
    for (j = 0; j < textCheckOK.length; j++)
    if (j == textCheckOK.length)
    {
    textAllValid = false;
    break;
    }
    if (ch != ",")
    allText += ch;
    }
    if (!allValid)
    {
    alertsay = "Please enter only these values \""
    alertsay = alertsay + textCheckOK + "\" in the \"" + textCheckStr.name + "\" field."
    alert(alertsay);
    return (false);
    }

    }
    else if ( text == "no" )
    {
    // only allow 0-9 be entered, plus any values passed
    // (can be in any order, and don't have to be comma, period, or hyphen)
    // if all numbers allow commas, periods, hyphens or whatever,
    // just hard code it here and take out the passed parameters.
    // Checks to ensure that only one period character was entered.
    var checkOK = "0123456789" + comma + period + hyphen;
    var checkStr = objName;
    var allValid = true;
    var maxDecPoints = 1;
    var decPoints = 0;
    var allNum = "";

    for (i = 0; i < checkStr.value.length; i++)
    {
    ch = checkStr.value.charAt(i);
    for (j = 0; j < checkOK.length; j++)
    if (ch == checkOK.charAt(j))
    {
    if (ch == ".")
    decPoints++;
    break;
    }
    //Checks to ensure that only one period character was entered.
    if (j == checkOK.length || decPoints > maxDecPoints)
    {
    allValid = false;
    break;
    }
    if (ch != ",")
    allNum += ch;
    }
    if (!allValid)
    {
    alertsay = "Please enter only these values \""
    alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
    alert(alertsay);
    return (false);
    }

    // set the minimum and maximum
    var chkVal = allNum;
    var prsVal = parseInt(allNum);
    if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
    {
    alertsay = "Please enter a value greater than or "
    alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
    alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
    alert(alertsay);
    return (false);
    }
    }
    }
    // End -->
    </script>

    <html>
    <body>
    <form action="store3.asp" method="post" name="Form1" onSubmit="return checkNumericForm(this,0,9999,' ','.',' ',' ')">
    Your name: <input name="UserName" type="text">
    PIN: <input name="PIN" type="text">
    <input type="submit" value="Submit" />
    </form>

    </body>
    </html>


    <!-- store3.asp -->

    <%
    dim fname
    fname=Request.Form("UserName")
    dim num
    num=Request.Form("PIN")
    If fname<>"" Then
    Response.Write("Hello " & fname & "!<br />")
    Response.Write("How are you today?")
    Response.Write("Your PIN is" & num)
    End If
    %>


Comments

  • Registered Users, Registered Users 2 Posts: 6,523 ✭✭✭daymobrew


    I recommend using regular expressions. To check for numbers your regular expression will probably be /^\d+$/ (string must be 1 or more numbers) and for letters /^[a-zA-Z]+$/ (string must 1 or more word chars).


  • Registered Users Posts: 36 or89


    thanks for your time and help:o


  • Registered Users, Registered Users 2 Posts: 6,523 ✭✭✭daymobrew


    You didn't list the errors you are getting.
    Have you run the code through a debugger? Put a load of alert() messages into the code.


Advertisement