PDA

View Full Version : how to check the same value about select menu



eliven
06-18-2010, 09:47 AM
Hi all
i've a select menu with value from a database, the values are only number, i need to put a control if the user has select the same number, and if yes put an alert, is possilble?

this is the select menu:



<form method="post" action="galleriaAdmin.asp">
<select name="posizione_<%=objRSFoto("id_foto")%>" id="posizione_<%=objRSFoto("id_foto")%>" title="seleziona la posizione">
<%
for cnt = 1 to maxPosition
%>
<option value="<%=cnt%>"<% if objRSFoto("gl_rank") = cnt then %> selected="selected"<% end if %>><%=cnt%></option>
<%
next
%>
</select>
</form>

thanks for your help :)
elisa

akitodito
06-18-2010, 01:17 PM
You reference the values of currently selected one like this:

var thevalue = document.FORMNAME.SELECTNAME.options[document.FORMNAME.SELECTNAME.options.selectedIndex].value

Or so it's easier to read:
var theselect = document.FORMNAME.SELECTNAME;
var thevalue = theselect.options[theselect.options.selectedIndex].value;

Change FORMNAME / SELECTNAME with the name of your form and select tag.

If you want the value passed to an onchange function etc then you can just use: this.options[this.selectedIndex].value

Hope that helps!

eliven
06-18-2010, 02:04 PM
You reference the values of currently selected one like this:

var thevalue = document.FORMNAME.SELECTNAME.options[document.FORMNAME.SELECTNAME.options.selectedIndex].value

Or so it's easier to read:
var theselect = document.FORMNAME.SELECTNAME;
var thevalue = theselect.options[theselect.options.selectedIndex].value;

Change FORMNAME / SELECTNAME with the name of your form and select tag.

If you want the value passed to an onchange function etc then you can just use: this.options[this.selectedIndex].value

Hope that helps!

like this:


<script language='javascript' type='text/javascript'>
var theselect = document.info.posizione;
var thevalue = theselect.options[theselect.options.selectedIndex].value;
</script>


where is the code for alert?

and the form is now:


<form method="post" action="galleriaAdmin.asp" name="info" id="info">
<select name="posizione_<%=objRSFoto("id_foto")%>" id="posizione_<%=objRSFoto("id_foto")%>" title="seleziona la posizione">
<%
for cnt = 1 to maxPosition
%>
<option value="<%=cnt%>"<% if objRSFoto("gl_rank") = cnt then %> selected="selected"<% end if %> onChange="this.options[this.selectedIndex].value"><%=cnt%></option>
<%
next
%>
</select>
</form>



but is not work :(, can you help me?
thanks
elisa