it's not working b/c you dont have your closing ")" on your if statement - the jquery wont run at all if your syntax isn't correct. read the above post
Please post your code for us to help!!
Mark Answered if it helps - Good luck!
Cheers!
Design And Align - Rob
nissan
Participant
1065 Points
618 Posts
valiadate Select List
Apr 12, 2012 05:28 PM|LINK
<select id="county"> <option value="">[Select a County]</option> <option value="Adams">Adams</option> <option value="Asotin">Asotin</option> </select>Rion William...
All-Star
31590 Points
5163 Posts
Re: valiadate Select List
Apr 12, 2012 05:32 PM|LINK
You could check the value upon your button click and if the value is "", then you know that your user didn't select an option. For example:
$("yourButton").click(function() { if($("#country option:selected").text() == "") { alert("Please select an option"); } else { //Perform other operations... } });robwscott
Star
8079 Points
1491 Posts
Re: valiadate Select List
Apr 12, 2012 05:36 PM|LINK
<select id="county"> <option value="0" Selected="true">[Select a County]</option> <option value="Adams">Adams</option> <option value="Asotin">Asotin</option> </select> <asp:Button .... class="someButton" /> $('.someButton').click( function() { var value = $('#county option:selected').val(); if (value == 0) { alert("error"); } });Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
nissan
Participant
1065 Points
618 Posts
Re: valiadate Select List
Apr 12, 2012 05:55 PM|LINK
I tried this, but its not going into the click function, I am I missing other block of code to initiate this click function?
robwscott
Star
8079 Points
1491 Posts
Re: valiadate Select List
Apr 12, 2012 06:21 PM|LINK
????
not understanding what you mean
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
nissan
Participant
1065 Points
618 Posts
Re: valiadate Select List
Apr 12, 2012 06:43 PM|LINK
This is how I have code.. but when I click.. nothing happens..
<asp:Content ID="Content1" ContentPlaceHolderID="mainContentPlaceHolder" runat="server">
<style type="text/css">
$(document).ready(function() {
$("#btnAddLoc").click( function()
{
alert("Hi");
if($("#county option:selected").text() == "")
{
alert("Please select a county");
}
});
});
</style>
.....
<select id="county">
<option value="" selected="true">[Select a County]</option>
<option value="Adams".......
robwscott
Star
8079 Points
1491 Posts
Re: valiadate Select List
Apr 12, 2012 06:50 PM|LINK
if your button is an asp button, you need
$('#<%=btnAddLoc.ClientID%>').click (function () {
.....
});
also your if statement wont work, you're missing your closing ")"
also. you need .val() not .text
which is why i had the "0" in there, and did
var value = $('#country option:selected').val();
if (value == "0")
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
nissan
Participant
1065 Points
618 Posts
Re: valiadate Select List
Apr 12, 2012 06:56 PM|LINK
Yes.. I changed like that.. still not working..
<script type="text/javascript">
$(document).ready(function () {
$('#<%=btnAddLoc.ClientID%>').click(function () {
alert("Hi");
if ($("#county option:selected").text() == "") {
alert("Please select a county");
}
});
});
</script>
robwscott
Star
8079 Points
1491 Posts
Re: valiadate Select List
Apr 12, 2012 07:03 PM|LINK
it's not working b/c you dont have your closing ")" on your if statement - the jquery wont run at all if your syntax isn't correct. read the above post
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
nissan
Participant
1065 Points
618 Posts
Re: valiadate Select List
Apr 12, 2012 07:18 PM|LINK
I changed as you suggested.. still not working.. Thank you for being patient with me though
<script type="text/javascript">
$(document).ready(function () {
$("#<%=btnAddLoc.ClientID%>").click(function () {
var value = $('#county option:selected').val();
if (value == 0) {
alert("Please select a county");
}
});
});
</script>
<select id="county">
<option value="0" selected="true">[Select a County]</option>
<option value="Adams"