| Author |
Validate Drop-Down Menu in a Form?
|
|
| macsrock27 2004-09-14, 12:16 pm |
| I have a form in which I have applied the Validate Form behavior to ensure that
the required fields have been filled out before submitting. No problem with the
text fields, but how do I make sure they choose a state from the drop-down menu?
The page with the form:
http://www.memoboardsrock.com/Conta...questquote.html
| |
| Mick White 2004-09-14, 12:16 pm |
| Last statement in <form> tag:
return (document.MM_returnValue && this.State.selectedIndex>0);
Mick
macsrock27 wrote:
> I have a form in which I have applied the Validate Form behavior to ensure that
> the required fields have been filled out before submitting. No problem with the
> text fields, but how do I make sure they choose a state from the drop-down menu?
>
> The page with the form:
>
> http://www.memoboardsrock.com/Conta...questquote.html
>
| |
| macsrock27 2004-09-15, 7:15 pm |
| My understanding of your reply was to insert:
return (document.MM_returnValue && this.State.selectedIndex>0);
in the <form> tag as the very last thing. I did, but you can still submit the
form without choosing a state. The text also shows up on the page itself. I
tried a few other placements (with the code of the previously existing validate
form behavior) and while of course you couldn't see it anymore (good) it still
wasn't working (not so good). Where precisely in the code should it go?
Thanks so much for your time, Mitch. I'm just a print designer doing my best
to design a site that showcases our products.
| |
| Gary White 2004-09-15, 7:15 pm |
| macsrock27 wrote:
> return (document.MM_returnValue && this.State.selectedIndex>0);
>
>
> in the <form> tag as the very last thing. I did, but you can still submit the
>form without choosing a state. The text also shows up on the page itself.
The following should all be on one line:
<form ... onClick="return (document.MM_returnValue &&
this.State.selectedIndex>0);">
Replace ... with your other form attributes.
Gary
| |
| macsrock27 2004-09-16, 10:25 am |
| I inserted where you said, and yes it prevents the form from being submitted if
a state is not selected. However, with the required text fields, if one is not
filled out and you try to submit, a warning box comes up explaining which
fields need to be filled in. With the state menu, no such box. It just won't
Submit. How do I make that dialogue box come up so a visitor filling out the
form knows they need to select a state?
If you need it:
http://www.memoboardsrock.com/Conta...tquotetest.html
| |
| macsrock27 2004-09-16, 10:25 am |
| Mick, if you see this I'm so sorry I called you Mitch ? and in a thank you too!
| |
| Gary White 2004-09-16, 4:10 pm |
| macsrock27 wrote:
>I inserted where you said, and yes it prevents the form from being submitted if
>a state is not selected. However, with the required text fields, if one is not
>filled out and you try to submit, a warning box comes up explaining which
>fields need to be filled in. With the state menu, no such box. It just won't
>Submit. How do I make that dialogue box come up so a visitor filling out the
>form knows they need to select a state?
I don't know what I was thinking. I'm surprised it's working at all.
Sorry, I just spaced out. Okay, there are a couple of things to do here.
First, remove the validate form behavior from your submit button.
Currently, it's being called twice. Next, remove the onClick code I told
you to put in the form tag. Awww ... never mind all that. Go to
http://apptools.com/newsgroup/visionmarketing.html and get the revised
page. You'll have to re-insert your images.
P.S. You may want to assign a background color to the page.
Gary
| |
| macsrock27 2004-09-16, 4:12 pm |
| Gary, you're awesome. Thanks so much for your time. It works just like I need
it.
The site has a number of our products which vary greatly in color, and so look
best on a white bg. This page is the same for consistency's sake. Thanks for
the suggestion though.
Following another member's inquiry I just happened to read your articles
regarding menus and jsmenu earlier today. I did not realize it was your site
until just now. This is only my 2nd site, and I started using P7's method for
menus the first go around. Before reading the articles I only realized some of
the benefits in doing so. Thanks for the informative articles!
| |
| Gary White 2004-09-16, 4:13 pm |
| macsrock27 wrote:
>Gary, you're awesome. Thanks so much for your time. It works just like I need
>it.
You're welcome. Glad I could help. One thing to keep in mind is that I
modified the MM_validateForm function. If you change the validation, it
will probably overwrite my change. The change was near the end of the
routine, where I replaced this:
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
With this:
}
if(document.quoteRequest.State.selectedIndex==0){
errors+='- You must select a state\n';
}
if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
If you save that somewhere, you can reapply the fix.
> The site has a number of our products which vary greatly in color, and so look
>best on a white bg. This page is the same for consistency's sake. Thanks for
>the suggestion though.
That's fine. My suggestion was because you have not *assigned* white to
be the background. In my browser, it shows up as a pink background.
> Following another member's inquiry I just happened to read your articles
>regarding menus and jsmenu earlier today. I did not realize it was your site
>until just now. This is only my 2nd site, and I started using P7's method for
>menus the first go around. Before reading the articles I only realized some of
>the benefits in doing so. Thanks for the informative articles!
You're welcome. Glad you found some of my rambling helpful.
Gary
| |
| macsrock27 2004-09-17, 12:37 am |
| Is it still pink?
If so, is there another page or two w/ pink bg's?
| |
| Gary White 2004-09-17, 12:37 am |
| macsrock27 wrote:
>Is it still pink?
Nope. It's white now. Don't forget that client side JavaScript
validation is a convenience to the user and can help lighten the server
load. It is NOT foolproof because a user with JavaScript disabled can
submit the form without the validation being executed. That's why you
still need server side validation.
Gary
|
|
|
|
| Copyright 2003 - 2009 forum4designers.com Software forum Computer Hardware reviews |