משיב מוביל
dropdownlist2 תלוי בערך שנבחר ב dropdownlist1

שאלה
-
הי!
אני כותבת קוד בvb.net וב asp.
יש לי שני dropdownlist,הראשון: ddlstate1 והשני ddlcat1.
ddlstate1 מוגדר באופן הבא:
<asp:DropDownList ID="ddlState1" runat="server" onchange="javascript:validate(this.name,this);"> <asp:ListItem Text="Select" /> <asp:ListItem Text="NY" /> <asp:ListItem Text="NJ" /> </asp:DropDownList>
אני צריכה שאם המשתמש בוחר בddlstate1 את הערך NY שddlcat1 יקבל את הערכים:
"search","municipals"
כש search צריך ליהיות ברירת במחדל.
ואם המשתמש בוחר בddlstate1 את הערך NJ שddlcat1 יקבל את הערכים:
"Search", "Rundown/Contin","Cover Record ","Other"
לאחר מכן אני צריכה לדעת/להחזיר את הערך שהמשתמש בחר ב ddlcat1.
זה מאד דחוף לי,
אם מישהו יכול לעזור לי,תודה רבה!
miritmann
- נערך על-ידי miritmann יום חמישי 06 דצמבר 2012 07:50
תשובות
-
תלמדי, זה חשוב!
html:
<select id="select1" onchange="setSelect2()"> <option value="0">Select</option> <option value="1">NY</option> <option value="2">NJ</option> </select> <select id="select2"> </select>
javascript:
function setSelect2() { debugger; //remode all the option in the select $('#select2') .find('option') .remove(); if ($("#select1").val() == "1") { //add new option to select $('#select2') .append($("<option></option>") .attr("search", "search") .text("search")); $('#select2') .append($("<option></option>") .attr("municipals", "municipals") .text("municipals")); } if ($("#select1").val() == "2") { //add new option to select $('#select2') .append($("<option></option>") .attr("Search", "Search") .text("Search")); $('#select2') .append($("<option></option>") .attr("Rundown/Contin", "Rundown/Contin") .text("Rundown/Contin")); $('#select2') .append($("<option></option>") .attr("Cover Record", "Cover Record") .text("Cover Record")); $('#select2') .append($("<option></option>") .attr("Other", "Other") .text("Other")); } }
לא לשכוח:
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
- סומן כתשובה על-ידי ipdd יום חמישי 06 דצמבר 2012 19:43
כל התגובות
-
אם יש לך פרטים מדויקים בתוך הDDL (וזה לא נלקח מהDB או משהו), אל תעשי את זה DDL.
תעשי את זה select רגיל של html.
ובonchange תשלחי אותו לjavascript ששואל על הערך ומכניס לפי זה ערכים לselect
ככה מכניסים ערכים לselect:
$('#mySelect') .append($("<option></option>") .attr("value",key) .text(value));
וככה מוחקים את כל הoptions:
$('#mySelect') .find('option') .remove()
-
-
תלמדי, זה חשוב!
html:
<select id="select1" onchange="setSelect2()"> <option value="0">Select</option> <option value="1">NY</option> <option value="2">NJ</option> </select> <select id="select2"> </select>
javascript:
function setSelect2() { debugger; //remode all the option in the select $('#select2') .find('option') .remove(); if ($("#select1").val() == "1") { //add new option to select $('#select2') .append($("<option></option>") .attr("search", "search") .text("search")); $('#select2') .append($("<option></option>") .attr("municipals", "municipals") .text("municipals")); } if ($("#select1").val() == "2") { //add new option to select $('#select2') .append($("<option></option>") .attr("Search", "Search") .text("Search")); $('#select2') .append($("<option></option>") .attr("Rundown/Contin", "Rundown/Contin") .text("Rundown/Contin")); $('#select2') .append($("<option></option>") .attr("Cover Record", "Cover Record") .text("Cover Record")); $('#select2') .append($("<option></option>") .attr("Other", "Other") .text("Other")); } }
לא לשכוח:
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
- סומן כתשובה על-ידי ipdd יום חמישי 06 דצמבר 2012 19:43
-
-
-
-
-
-
תודה על התגובה,
אבל הוא אפילו לא מגיע עד לשם:
function setSelect2() { debugger; ********************************************************** עד לפה הוא מבצע,מכאן והלאה הוא מתעלם... //remode all the option in the select $('#select2') .find('option') .remove(); if ($("#select1").val() == "1") { //add new option to select $('#select2') .append($("<option></option>") .attr("search", "search") .text("search")); $('#select2') .append($("<option></option>") .attr("municipals", "municipals") .text("municipals")); } ....
החלפתי את זה $('#select2') במה שכתבת אבל גם זה לא עזר...
אני קוראת לפונקציה הזו מתוך פונקצית javascript אחרת ושולחת כפרמטר את ה ddlstate ואת ה select, (ולא ddl), בשם cat1
function setSelect2(ddlState1,ddlcat1) { debugger; alert("i am here1"); //remove all the option in the select $('#ddlcat1') .find('option') .remove(); alert("i am here2"); if ($("#ddlState1").val() == "Search") { //add new option to select $('#ddlcat1') .append($("<option></option>") .attr("search", "search") .text("search")); $('#ddlcat1') .append($("<option></option>") .attr("municipals", "municipals") .text("municipals")); } if ($("#ddlState1").val() == "Municipals") { //add new option to select $('#ddlcat1') .append($("<option></option>") .attr("Search", "Search") .text("Search")); $('#ddlcat1') .append($("<option></option>") .attr("Rundown/Contin", "Rundown/Contin") .text("Rundown/Contin")); $('#ddlcat1') .append($("<option></option>") .attr("Cover Record", "Cover Record") .text("Cover Record")); $('#ddlcat1') .append($("<option></option>") .attr("Other", "Other") .text("Other")); } } </script>
ואני קוראת לפונקציה הזו מתוך פונקציה javascript אחרת:
setSelect2 (ddlState.name, cat.name);
- נערך על-ידי miritmann יום שני 10 דצמבר 2012 07:43