Form trap problem

G

Garry Jones

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
 
M

McKirahan

Garry Jones said:
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
 
R

RobG

McKirahan said:
"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)" ...>
 
G

Garry Jones

"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
 
G

Garry Jones

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top