homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Need a bit of Form Field JavaScript Help
Please :)
nutsandbolts

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 207 posted 6:33 pm on Oct 8, 2002 (gmt 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...

 

txbakers

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



 
Msg#: 207 posted 6:44 pm on Oct 8, 2002 (gmt 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>

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 207 posted 6:52 pm on Oct 8, 2002 (gmt 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

nutsandbolts

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 207 posted 6:53 pm on Oct 8, 2002 (gmt 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...

moonbiter

10+ Year Member



 
Msg#: 207 posted 7:00 pm on Oct 8, 2002 (gmt 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>

nutsandbolts

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 207 posted 7:22 pm on Oct 8, 2002 (gmt 0)

Thanks! I will give it a shot....

txbakers

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



 
Msg#: 207 posted 12:43 am on Oct 9, 2002 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved