javascript alert if set value it displayed in a select list

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

javascript alert if set value it displayed in a select list

Post by jonnyfortis »

i have a select list that is populated from a php mysql DB. if the words. " finished" are entered into the select lost ( from the backend) when the user selects the word "finished" and try's to submit the for i need an alert to say " sorry you cant select this option"


how can this be done

thanks in advance
Last edited by jonnyfortis on Mon Sep 17, 2012 4:33 am, edited 3 times in total.
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: java alert if a set value it displayed in a select list

Post by Gopesh »

Hi,
First off all change the title from java to javascript bcoz java and javascript are entirely different.
try this

Code: Select all

$(function() {
$('#selectlistid').change(function() {
var value = $(this).val();
if (value=='finished'){
alert("Message");
}else{
}
});
});
Hope that u uses jquery.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: java alert if a set value it displayed in a select list

Post by jonnyfortis »

sorry about that , yes i know tey are different, i was rushing..
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: javascript alert if set value it displayed in a select l

Post by jonnyfortis »

ok so i add this javascript then in the form add a function?

can i do it that if the field has more than "finshed" in the text string it will just recognize that word

e.g if in the select list it as 2-4 years (finished) it will recognize this aswell?
Post Reply