Helow
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
page
so how to do that?
JS problem...
Moderators: egami, macek, gesf
it would be helpful to post some code.
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?
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?
the values of the option are stored in
selectname.options
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[i].value == textname.value)
{
alert("Value is already in list");
return false;
}
}
return true;
}
selectname.options
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[i].value == textname.value)
{
alert("Value is already in list");
return false;
}
}
return true;
}