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 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

Help With This?

  • 22-10-2008 9:40am
    #1
    Posts: 0


    I wonder if people could help me with this.

    I've gotten my error trap working and there's various functions I have which check different things- mostly it's checking if text has been entered.

    Here's a sample of one of the functions:
    function secondnamefun()
    { 
     if (document.cardform.secondname.value.length == 0)
       {
         alert("Please fill out your second name.\n");
         subtoterror++;
         return subtoterror;
       }
    }
    

    and the line that calls it is here
    <input type = "text" name = "secondname" value ="" onblur = "secondnamefun()">
    

    At the end of the website, what I would like to happen is when you click the submit button, it enters a function which checks the variable subtoterror. If its greater than 0, it transfers to a page that says "there were errors", if not, it transfers to a page that says "all clear" or whatever.

    the code for the button is here
    <input type="button" name="submit" value="Submit" onClick= "formcheckfun(subtot)">
    

    and the function is here
    function formcheckfun(subtot)
    { 
      if (document.cardform.subtot.value == 0)
       {
        window.navigate('formprocessed.html');
       }
    }
    

    At the top of the page I have
    subtoterror = 0;
    subtoterror = document.cardform.subtot;
    

    Is what I am trying to do possible, and if it is, am I doing it right?


Comments

  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    As I said in your other thread, client side validation is not enough - you must validate on the server as well.

    Don't have much time to look at your code, but this bit:

    subtoterror = 0;
    subtoterror = document.cardform.subtot;

    The second line will always overwrite the first line. If there isn't a numeric value in that form field, then I think you may run into problems if you are incrementing it.


  • Posts: 0 [Deleted User]


    I'm not entirely sure how you mean by validate on the server. There's a chance that this site will never go live, it's just for a college project.


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    I meant that all input should be validated by the back-end code, as you can't rely on all the info you get from a browser. JavaScript can be disabled instantly, which will mean your validation won't run.


  • Posts: 0 [Deleted User]


    Ah ok.

    Would that be why some websites have the [noscript]? Sorry, the lecturers are generally having us do our own work, and learning I'm learning this from scratch.


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Sort of - <noscript> just displays text to browsers that don't have JavaScript enabled. It's a throwback to a good few versions ago.


  • Advertisement
  • Posts: 0 [Deleted User]


    So I should have validation in the html as well as the javascript? Man, this is getting a lot more complicated than I had originally thouhg. Ha.


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    So I should have validation in the html as well as the javascript? Man, this is getting a lot more complicated than I had originally thouhg. Ha.

    No, you can't validate with HTML. You need to validate with the scripting/programming language that runs on the webserver, as you know it will always run.

    To take a simple ASP example:
    <%
    If Request.Form("name") = "" Then
        Response.Write("Please enter your name")
    End If
    %>
    

    This code is executed by the webserver, not the browser - so it doesn't matter what browser you have, whether JavaScript is enabled etc.

    If you view the HTML source of the page, you won't see that code at all because it is executed on the server before it reaches the browser.

    To take another example - suppose you want to display a message after a certain date. If you do that in JavaScript, then it will use the browsers date. That could be a big problem if you there is a cut-off date for an ordering page. Someone with an incorrect date on their PC could get pass that message.

    If you do it on the webserver, it will use the server's date.


  • Registered Users, Registered Users 2 Posts: 569 ✭✭✭none


    Yes, what you're doing is quite common as JavaScript validation is still important in many cases. Just make sure you're talking about a page as opposed to a site which you mentioned. If all your functions and variables are on one page, it is possible and even recommended (in some cases) to validate some basic stuff, e.g., empty fields or numbers. If your want your validation to span several pages, i.e., a site, you may have problems with passing JavaScript variables between pages. Remember that if you don't have a server side support (believe you're not the only one here), JavaScript is your only friend. Even if you do use some server side technology, using client side validation can help to take some load off your server which is one of the main concerns in eCommerce and other Web services.


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    I agree with that - I was not saying that server side validation should replace JavaScript, but that JavaScript is a nice-to-have which should only be treated as something that might take some load off the server, and be a bit more user-friendly.


  • Posts: 0 [Deleted User]


    I've gotten all the validation working and was just wondering if it would be possible to write a file to the computer using javascript. I know it would be better using different languages, but for now that's what I would like to stick with- maybe next year this will change.

    Google searching for tutorials came up with nothing.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 569 ✭✭✭none


    No, otherwise it would be a big security issue.


Advertisement