...

View Full Version : combo box values?



nikko50
11-30-2009, 03:25 PM
I have 2 combo boxes where you can move the items in combo box 1 to combo box 2. I want to validate that combo box 2 actually has something moved to it. How can I count the items in combo box 2. Combo box 2 will initially have no items in the box on page load. It is up to the user to move the items to combo box 2 and I want to make sure at least 1 item was moved.

Kor
11-30-2009, 03:46 PM
Post the code. HTML and Javascript. Or post a link to a test page.

Old Pedant
11-30-2009, 09:58 PM
First of all, there's no such thing as a "combo box" in HTML. That's an MSIE thing that allows you to *either* select from a dropdown *or* type in a new value. You can simulate that in HTML using JavaScript and both an <input type="text"> and <select>. Is *that* what you are talking about????

Or do you really mean you have simply a pair of <select>s???

If so, it's easy.

Just do something like this:


function validateForm(form)
{
var found = false;
for ( var i = 0; i < form.two.options.length; ++i )
{
if ( form.two.options[i].selected ) found = true;
}
if ( ! found )
{
alert("You must choose at least one widget");
return false;
}
... other form validation here ...

return true; // if all validation succeeds
}

...

<form ... onsubmit="return validateForm(this);">
...
<select name="one">
...
</select>
...
<select name="two">
...
</select>

DTD13
12-01-2009, 01:16 AM
How anybody suppose to help when "OldPend.." taking them all. Dang :p!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum