Problum In Javascript
-
Hi All My Friends, I Have 2 problems in a javascript. 1: I am not getting the Item Count Of Dropdown List. 2: I am calling javascript on Button "OnClientClick" event,then also onclick event is fired even script returning false. Hav a look on Script function validate() { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex == 0) { alert("Select a Category name !") document.getElementById("<%=ddlCategories.ClientID%>").focus() return false; } else if (document.getElementById("<%=txtText.ClientID%>").value == "") { alert("Please fill the Message field !") document.getElementById("<%=txtText.ClientID%>").focus() return false; } else { if (SubcategoryCount > 0) { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex != 0 && document.getElementById("<%=ddlSubCategories.ClientID%>").selectedIndex == 0) { alert("Select a Sub-Category name !") return false; } } } }
-
Hi All My Friends, I Have 2 problems in a javascript. 1: I am not getting the Item Count Of Dropdown List. 2: I am calling javascript on Button "OnClientClick" event,then also onclick event is fired even script returning false. Hav a look on Script function validate() { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex == 0) { alert("Select a Category name !") document.getElementById("<%=ddlCategories.ClientID%>").focus() return false; } else if (document.getElementById("<%=txtText.ClientID%>").value == "") { alert("Please fill the Message field !") document.getElementById("<%=txtText.ClientID%>").focus() return false; } else { if (SubcategoryCount > 0) { if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex != 0 && document.getElementById("<%=ddlSubCategories.ClientID%>").selectedIndex == 0) { alert("Select a Sub-Category name !") return false; } } } }
Sachin Dubey wrote:
if (SubcategoryCount > 0) {
Where you got this SubcategoryCount from?:confused: Its good if you can make your code little bit readable to the forum readers. :)
Arun Jacob http://codepronet.blogspot.com/
-
Sachin Dubey wrote:
if (SubcategoryCount > 0) {
Where you got this SubcategoryCount from?:confused: Its good if you can make your code little bit readable to the forum readers. :)
Arun Jacob http://codepronet.blogspot.com/
That is only i asked in first question.. I Have ddlSubCategories in Page
-
That is only i asked in first question.. I Have ddlSubCategories in Page
Sachin Dubey wrote:
That is only i asked in first question
that i know. :) What i am asking is, in your code you have a line of code like,SubcategoryCount>0, Whats SubcategoryCount?Is it a global variable?How you are assigning value for that?
Arun Jacob http://codepronet.blogspot.com/
-
Sachin Dubey wrote:
That is only i asked in first question
that i know. :) What i am asking is, in your code you have a line of code like,SubcategoryCount>0, Whats SubcategoryCount?Is it a global variable?How you are assigning value for that?
Arun Jacob http://codepronet.blogspot.com/
That is not any Variable...That is just i written... But I want to Use ddlSubcategories.Items.Count in place of SubCategoryCount.. But I Am not Getting the value... Actually if user doesnt select category then Select Category alert will Prompt..If User Selected Category And There is no Subcategory of that then we allow him to proceed...But if that category has some Sub Categories then its must to Select SubCategory... Thats what i Want in Else Condition u see...
-
That is not any Variable...That is just i written... But I want to Use ddlSubcategories.Items.Count in place of SubCategoryCount.. But I Am not Getting the value... Actually if user doesnt select category then Select Category alert will Prompt..If User Selected Category And There is no Subcategory of that then we allow him to proceed...But if that category has some Sub Categories then its must to Select SubCategory... Thats what i Want in Else Condition u see...
Sachin Dubey wrote:
That is not any Variable...That is just i written...
How we know its simply written. :) Ok.Try ddlSubCategory.options.length
Arun Jacob http://codepronet.blogspot.com/
-
Sachin Dubey wrote:
That is not any Variable...That is just i written...
How we know its simply written. :) Ok.Try ddlSubCategory.options.length
Arun Jacob http://codepronet.blogspot.com/
Thanks Arun I Got The count By : if (document.getElementById("<%=ddlSubCategories.ClientID%>").options.length > 1) Now its showing the message also...But Its Saving the record ... My Code of Button is: After reading that script it reading On_click event Code... How to Tackele that..
-
Thanks Arun I Got The count By : if (document.getElementById("<%=ddlSubCategories.ClientID%>").options.length > 1) Now its showing the message also...But Its Saving the record ... My Code of Button is: After reading that script it reading On_click event Code... How to Tackele that..
Sachin Dubey wrote:
OnClientClick="javascript:validate();"
Instead try this, OnClientClick="return validate();"
Arun Jacob http://codepronet.blogspot.com/
-
Sachin Dubey wrote:
OnClientClick="javascript:validate();"
Instead try this, OnClientClick="return validate();"
Arun Jacob http://codepronet.blogspot.com/
Hey Arun... It Works... Thanks A Lot.... :)