Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: open

Message Too Old, No Replies

Need a bit of Form Field JavaScript Help

Please :)

     
6:33 pm on Oct 8, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 22, 2002
posts:959
votes: 0


I have a form field that requires an amount no lower than the number 25 to be entered into it.

So I need a small bit of JavaScript to make sure this is the case (as people are still, despite requests, putting in lower values!)

The input bit of the form is below - can the JavaScript be small enough to fit onto that line without needing a whole heap of code?

<input type="text" name="amount" value="25" size=10>

If anyone can help, I would appreciate it :)

Many thanks...

6:44 pm on Oct 8, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


<input type="text" name="amount" value="25" size=10 onChange="verify(this.value)">

<script type="text/javascript">
function verify(val){
if (val <= 25) {
alert("Your number is less than 25, try again");
document.formname.boxname.focus();
}
}</script>

that should do it for you. Put the script in the <head>

6:52 pm on Oct 8, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


I hope you donīt rely on that JavaScript check. You always need to check user submitted data on the server. That is why I donīt bother with JavaScript checks.

Andreas

6:53 pm on Oct 8, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 22, 2002
posts:959
votes: 0


Great - that works, thank you!

How difficult would it be to not allow the person to press submit and continue until they have put a value higher than 25? At the moment it does give that pop-up warning, but they can still press submit and go ahead...

7:00 pm on Oct 8, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:May 1, 2002
posts:351
votes: 0


Your submit button:

<input type="submit" name="submitName" disabled="disabled" />

and in the javascript:

<script type="text/javascript">
function verify(val){
if (val <= 25) {
alert("Your number is less than 25, try again");
document.formname.boxname.focus();
} else {
document.formname.submitName.disabled = false;
}
}</script>
7:22 pm on Oct 8, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 22, 2002
posts:959
votes: 0


Thanks! I will give it a shot....
12:43 am on Oct 9, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


To andreas' comment above - absolutely you must validate from the server if it is that critical that the data be correct.

I use client side validation only for "oops" catching - not enough digits in a phone number or zip, bad date format, etc.

Serious validation - duplicate keys, totally bogus entries, have to be validated on the server. For the oops entries, it's not mission critical that the data be correct, the user would be upset later if the phone number he entered showed up as 6 digits, but that's his problem.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members