...

View Full Version : Compare Input String In HTML



Sengz
01-15-2013, 02:33 PM
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 :/

VIPStephan
01-15-2013, 03:10 PM
This is not possible with HTML, you need some server side scripting language like PHP, ASP.NET, JSP, just to name a few.

COBOLdinosaur
01-15-2013, 05:55 PM
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.

VIPStephan
01-15-2013, 06:31 PM
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.

WolfShade
01-15-2013, 07:17 PM
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.

felgall
01-15-2013, 07:39 PM
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.

COBOLdinosaur
01-15-2013, 07:59 PM
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.

LearningCoder
01-15-2013, 08:13 PM
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.

VIPStephan
01-15-2013, 09:54 PM
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.

COBOLdinosaur
01-15-2013, 09:56 PM
Okay, a lack of clarity on my part.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum