Page 1 of 1

JS problem...

Posted: Thu Jun 05, 2003 12:29 am
by CrustyDOD

I have a big problem i think:)

i get my data from DB with php and then
I display them in DropDown box...

So now i wanted to check with JS if the name
already exists in that dropdown, when i click
the button, if the name already exists then
some error message displays, else go to next

so how to do that?

Posted: Fri Jun 06, 2003 4:51 am
by Redcircle
it would be helpful to post some code.

Posted: Fri Jun 06, 2003 5:07 am
by CrustyDOD
what code?
how do i get data from DB with PHP?

if u meant JS code i don't have any, cause i don't know how to write that.

<option value="2">test</option>
<option value="4">crap</option>
<option value="12">what</option>
and so on...

now i want to check with JavaScript if the name that i entered in edit box already exists in this dropdown menu NOT value (2), but name (ex: test)!

if the name in dropdown menu exists then show javascript alert else go to next page...

this is all in one form...

is this more clear?

Posted: Fri Jun 06, 2003 5:54 am
by Redcircle
the values of the option are stored in


so you can do a loop through them to see if they exist.

here's a function that should work for you I haven't tested it but it might help you out a little.

boxname is your select box and textname is your edit box

function checkInBox(boxname,textname)
for(i=0; i<boxname.options.length; i++)
if(boxname.options.value == textname.value)
alert("Value is already in list");
return false;
return true;