[thelist] JavaScript Select box validation style problem

Chris spam at cimmanon.org
Fri Nov 5 11:52:37 CST 2004


On Fri, 05 Nov 2004 11:00:55 -0600, Jay Fitzgerald <jayfitz at bayou.com>  
wrote:

> Yes, I found that placing borders around select boxes does not work...so  
> now I am trying to change the background color and font color of the  
> first option in my select box if the validation fails:
>
> function checkstep1()
> {
>     var mm = document.step1.mm;
>     var backgroundColor = '#ff0000';
>     var color = '#ffffff';
>
>     if(mm.options[mm.selectedIndex].value = "00")
>     {
>         alert('Please select the month');
>         mm.options[mm.selectedIndex].style = backgroundColor;
>         mm.options[mm.selectedIndex].style = color;
>         return false;
>     }
>
> but I am doing this correctly. It sortof validates the form because it  
> gives the JS Alert box; but it still process the form and goes to the  
> next page and it soent stop and set the background and font colors
>
> Any help is appreciated.
>
> Jay
>

It sounds like maybe the alert box is causing the form submission when you  
hit "ok".

See if this is useful:
http://www.onlinetools.org/articles/unobtrusivejavascript/chapter5.html

Sample form:
http://www.onlinetools.org/articles/unobtrusivejavascript/ex_form.html

-- 
chris


More information about the thelist mailing list