dropdownlist not validating....javascript code

Posted by Ankitsrist under ASP.NET on 12/20/2012 | Points: 10 | Views : 2157 | Status : [Member] | Replies : 6
dropdownlist not validating please help my code as follows

<script language="javascript" type="text/javascript">
function validate()
{
if(document.getElementById("<%=DropDownList1.ClientID%>").value=="0")
{
alert("please select");
//document.getElementById("<=%DropDownList1.ClientID%>").focus();
return false;
}
if(document.getElementById("<%=TextBox1.ClientID%>").value=="")
{
alert(please enter);
//document.getElementById("TextBox1").focus();
return false;
}
}





Responses

Posted by: Ranjeet_8 on: 12/20/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this

<script type="text/javascript">
function validate() {
var e = document.getElementById('<%= DropDownList1.ClientID %>');
var strVal = e.options[e.selectedIndex].value;
if (strVal == "0") {
alert('please select');
return false;
}
return true;
}
</script>


Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 12/20/2012 [Member] Bronze | Points: 25

Up
0
Down
function chkDropDownList(object,msg)
{

var elm=getObj(object);

if(elm.selectedIndex == 0)
{ alert("Select " + msg + "!!!");
elm.focus();
return false;
}return true;
}

if(!chkDropDownList('<%=ddlPosition.ClientID %>','Job Applied For'))
return false;

Thanks
Pavan Kumar
Mark Answer if this fits the need

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandeepmhatre on: 12/20/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeepmhatre.blogspot.com/2011/12/javascript-validation-for-dropdown-list.html

Sandeep M,
Software Developer
Follow me on :
http://sandeepmhatre.blogspot.in

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manoj_B on: 12/21/2012 [Member] Starter | Points: 25

Up
0
Down
hii...
try d follwing code..

<script language="javascript" type="text/javascript">


function validate()

{

if(document.getElementById("DropDownList1").selectedIndex =="0")

{

alert("please select");
document.getElementById("DropDownList1").focus();
return false;

}

}


Thanks & Regards
Manoj Kumar

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 12/22/2012 [Member] Starter | Points: 25

Up
0
Down
if(document.getElementById("<%=DropDownList1.ClientID%>").value=="")
{
alert("please select");
}

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 12/22/2012 [Member] Starter | Points: 25

Up
0
Down
thanks every one....we can also try this

function validate()

{
if(document.getElementById("<%=DropDownList1.ClientID%>").value=="0")
{
alert("please select state");

return false;
}


Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response