469,271 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Form trap problem

I want to ensure the users choose an item from a drop down list.
The preselected value is "Not Chosen"

Using script I cloned this from other working code, but it is broken
somewhere.

function checkform ( form )
{
if (form.ctsz.value == "Not Chosen") {
alert( "Choose Size or choose opt out" );
form.ctsz.focus();
return false ;
}
return true ;
}

Any help appreciated.

Garry Jones
Sweden

Oct 5 '06 #1
5 1142
"Garry Jones" <ga*********@morack.sewrote in message
news:eg**********@yggdrasil.glocalnet.net...
I want to ensure the users choose an item from a drop down list.
The preselected value is "Not Chosen"

Using script I cloned this from other working code, but it is broken
somewhere.

function checkform ( form )
{
if (form.ctsz.value == "Not Chosen") {
alert( "Choose Size or choose opt out" );
form.ctsz.focus();
return false ;
}
return true ;
}

Any help appreciated.
"broken somewhere" is not very helpful to us.

What does your form look like? Does it ihave:
<form onsubmit="checkForm(this)" ...>
and
<select name="ctsz" ...>
and
<input type="submit" ...>

Try using the Firefox browser to debug JavaScript.
http://www.getfirefox.com
Oct 5 '06 #2

McKirahan wrote:
"Garry Jones" <ga*********@morack.sewrote in message
news:eg**********@yggdrasil.glocalnet.net...
I want to ensure the users choose an item from a drop down list.
The preselected value is "Not Chosen"

Using script I cloned this from other working code, but it is broken
somewhere.

function checkform ( form )
{
if (form.ctsz.value == "Not Chosen") {
alert( "Choose Size or choose opt out" );
form.ctsz.focus();
return false ;
}
return true ;
}

Any help appreciated.

"broken somewhere" is not very helpful to us.

What does your form look like? Does it ihave:
<form onsubmit="checkForm(this)" ...>
That would need to be:

<form onsubmit="return checkForm(this)" ...>
--
Rob

Oct 5 '06 #3
"RobG" <rg***@iinet.net.auwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
What does your form look like? Does it ihave:
<form onsubmit="checkForm(this)" ...>

That would need to be:

<form onsubmit="return checkForm(this)" ...>
Good catch.
Oct 5 '06 #4
"broken somewhere" is not very helpful to us.

I have the checkform parameter and all values declared.

I have been using a java code script to test for an empty field.

This line of code results in the alert being triggered if the value is not
entered

if (form.deltport.value == "")

I have only ever tested for empty fields and assumed thought I could adapt
that code to test for a value.

I want to test for the value of an option from a "select" control.

Following the above example it should follow that this line of code

if (form.ctsz.value == "Not Chosen")

..... triggers an alert if the value is Not Chosen - but it does not work-

Greatful for any help in this matter.

Garry Jones
Sweden
Oct 6 '06 #5
"Garry Jones" <ga*********@morack.seskrev i meddelandet
news:eg**********@yggdrasil.glocalnet.net...
if (form.ctsz.value == "Not Chosen")
Sorry, I have been stupid (again).

I should not have tested for the text of the select control but the value
submitted by the option.

Now working, sorry to have wasted your time.

Garry Jones
Sweden
Oct 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Carl Tribble | last post: by
15 posts views Thread by Dominic Tocci | last post: by
8 posts views Thread by Emily Jones | last post: by
17 posts views Thread by Jim Little | last post: by
18 posts views Thread by Colin McGuire | last post: by
3 posts views Thread by Gavin | last post: by
19 posts views Thread by zacks | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.