JS problem...

Javascript coding ..

Moderators: macek, egami, gesf

CrustyDOD
New php-forum User
New php-forum User
Posts: 13
Joined: Tue Oct 29, 2002 2:58 am

JS problem...

Postby CrustyDOD » Thu Jun 05, 2003 12:29 am

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?

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Fri Jun 06, 2003 4:51 am

it would be helpful to post some code.

CrustyDOD
New php-forum User
New php-forum User
Posts: 13
Joined: Tue Oct 29, 2002 2:58 am

Postby CrustyDOD » Fri Jun 06, 2003 5:07 am

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?

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Fri Jun 06, 2003 5:54 am

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;


}


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 0 guests