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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Compare Input String In HTML

    Hi guys,

    I would like to know how can I compare a string that is input by the user.

    Then, if the variable are true, it will continue to redirect.

    If the variable key in by the user is wrong, it will remain on the page and shows prompt and error to the user.

    Please help out with this, since I search it in the web I got no luck :/

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,876
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    This is not possible with HTML, you need some server side scripting language like PHP, ASP.NET, JSP, just to name a few.

  • #3
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    411
    Thanks
    2
    Thanked 32 Times in 32 Posts
    You could also validate it with javascript on the client using an onsubmit event to test and display an error or submit if the input is okay.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,876
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    Quote Originally Posted by COBOLdinosaur View Post
    You could also validate it with javascript on the client using an onsubmit event to test and display an error or submit if the input is okay.
    But only after a server side solution has been employed.

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Quote Originally Posted by VIPStephan View Post
    But only after a server side solution has been employed.
    Perhaps not. You _could_ do it with plain HTML and JavaScript by using JS to "redirect" to the next page(s) and applying URL parameters to keep data across pages.

    It wouldn't be as good as a SS solution; but it could be done.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by WolfShade View Post
    Perhaps not. You _could_ do it with plain HTML and JavaScript by using JS to "redirect" to the next page(s) and applying URL parameters to keep data across pages.
    You cannot do form validation only with JavaScript. All anyone would need to do to bypass all the validation is to disable JavaScript for that web page. You need to have a server side solution in place to do the validation when someone does that or they will be able to enter whatever they like.

    If turning off JavaScript prevents the page from working then your page is automatically broken for everyone who doesn't have JavaScript enabled in the first place.

    Any JavaScript method of passing data between pages can be overridden by the person simply changing the values being passed without regard to any validation that might have been applied beforehand - the only way to ensure that the data passed is valid is to validate on the server from the following page before displaying the page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    411
    Thanks
    2
    Thanked 32 Times in 32 Posts
    I was not advocating no server side validation. I was suggesting that validation could be done and submit only when validation passes as a means of reducing traffic. There is no circumstance where validation of input should not be done on the server, but doing client side pre-processing reduces traffic.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #8
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    924
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Sengz, do you know any Serverside language, even the basics?

    I agree with COBOL to a certain extent but you can never guarantee that JavaScript is enabled. I do all validation of forms with PHP now as it gives you the comfort of knowing that even if someone does turn off JavaScript, it's not going to affect your form processing in the slightest. You can retrieve and display the form input value with 1 line of code in PHP (although granted, you would have to do extra validation to make sure your user entered what you want). Again, redirecting someone with PHP is just 1 more line of code.

    What are your thoughts after hearing all the advice?

    Regards,

    Lc.

  • #9
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,876
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    Quote Originally Posted by COBOLdinosaur View Post
    I was not advocating no server side validation.
    And I wasn’t saying it can’t be done with JS. However, especially newbies should not be taught the “wrong” solutions in the first place. Telling someone without experience that JavaScript can be used might give them the wrong ideas about the possibilities and insufficiencies of certain methods.

  • #10
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    411
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Okay, a lack of clarity on my part.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&


  •  

    Posting Permissions

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