Validating user input

Discussion in 'PHP' started by knightrider, Sep 15, 2007.

  1. #1
    Hi. I´m developing a simple web site with PHP and MySQL. I work on WIN XP but the site will be used on some LINUX version. I used JavaScript to validate the data input by the users. My question is: Does JavaScript work on LINUX? If it doesn´t what shuold I use?

    I´m using something like this.

    I WANNA BE CLEAR. I´m only after the answer. This code works fine in XP.





    SCRIPT TYPE="text/javascript">
    <!--
    // check that they entered an amount tested, an amount passed,
    // and that they didn't pass units than they more than tested


    function TestDataCheck()
    {
    var qtytested = parseInt(document.testform.qtytested.value);
    var qtypassed = parseInt(document.testform.qtypassed.value);
    var returnval;

    if ( (qtytested >= 1) && (qtypassed >= 0) && (qtytested >= qtypassed))
    returnval = true;
    else
    {
    alert("must enter the quantity tested and that amount or fewer for quantity passed");
    returnval = false;
    }

    return returnval;
    }
    // -->
    </SCRIPT>

    <FORM
    ACTION="tres.htm" NAME="testform" onSubmit="return TestDataCheck()"
    >
    units tested: <INPUT NAME="qtytested" SIZE=3><BR>
    units passed: <INPUT NAME="qtypassed" SIZE=3><P>
    <INPUT TYPE=SUBMIT VALUE="Submit">
    </FORM>
     
    knightrider, Sep 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    JavaScript is a browser based language and doesn't depend on operating systems. However, you should never rely on client-side validation alone, as it can be disabled by the user and he could pretty much do whatever he wants.

    Always use a server-side language to validate the user's input. You can additionally use Javascript to make it more comfortable for the user, and to avoid useless server load.
     
    nico_swd, Sep 15, 2007 IP
  3. knightrider

    knightrider Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you sure It won´t have troubles with FireFox.
     
    knightrider, Sep 15, 2007 IP
  4. Rogem

    Rogem Peon

    Messages:
    171
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Javascript should work on Linux. One would assume it would be the browser what would be the problem.
     
    Rogem, Sep 15, 2007 IP
  5. knightrider

    knightrider Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you. I don´t use LINUX.
     
    knightrider, Sep 15, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    All versions of Firefox support JavaScript.

    Though, all browsers have their own way of parsing and handling the code. So certain things need to be coded differently for some browsers. But your code doesn't seem to be affected by this.
     
    nico_swd, Sep 15, 2007 IP
  7. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes.

    If the user is using a browser with javascript support and has it enabled (which is the case most of the time).
     
    HypertextFever, Sep 16, 2007 IP