The picklist(s) is in support of a form. Half of my users come to the page with a promotion code in hand, and others just want to look up the promotion code. That's why the picklist is not part of the form.
If i can capture the picked values of theprimary list and also the secondary list into variables I can move forward.
actually I will populate the selected option into the donate text box.
Since you are most likely going to be submitting this anyways - a good idea may be to create a hidden field (or two) within your form and then when any of the drop-downs are changed you can update the values within your form accordingly.
By doing this, whenever you perform your submit you can check which values were selected :
<form>
<!-- Your other fields in your form -->
<input id='np_hidden' type='hidden' />
<input id='event_hidden' type='hidden' />
</form>
along with this jQuery code :
$(document).ready(function(){
//When any of the drop-down boxes are changed, update the values accordingly
$('select').change(function(){
$("#np_hidden").val($("#NpId").val());
$("#event_hidden").val($("#EventId").val());
});
});
The value passed is the "Id" of the selected table entry, not the text value needed. Can I pull the text field value within this function (it's on the screen, I should be able to get to it) or do I need to point the function to another file "CasCadingValue.cshtml"
and pass the selected Id to a database querysingle then take that result and populate a global variable then somehow get back to this calling page.
Can you post some of your rendered markup? I can't tell exactly what you are trying to target with the following jQuery selector :
$("Event.DonateCode?#EventId").val();
As the syntax within the selector looks like it might be incorrect. If you are trying to get the selected text within your #EventId drop-down, then you will want to use :
DMT20601
Member
86 Points
197 Posts
Webmatrix - Pulling the result of a drop down list.
Jan 21, 2013 09:32 PM|LINK
I'm working with Webmatrix and the Starter Site.
I have a working cascading drop down list. The list is not part of a form.
After the user has made their choice, how do you capture the selected value of each list?
Thanks
Dallas in Maryland
<div> <div id="nonprofit-picklist-label">Participating Nonprofits</div> <div id="nonprofit-picklist-value"> <select id="NpId" name="NpId"> <option value="">-- Select Nonprofit --</option> @foreach(var np in nplist){ <option value="@np.NpId">@np.NpName</option> } </select> </div> <div id="event-picklist-label">Donate Code for Event </div> <div id="event-picklist-value"> <select id="EventId"> <option value="">-- Select Event --</option> </select> </div> </div>Rion William...
All-Star
27716 Points
4574 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Jan 21, 2013 09:35 PM|LINK
How would you prefer to retrieve the value? Through Javascript / jQuery (such as an alert?) or by actually submitting the form?
Very Simple jQuery Example
DMT20601
Member
86 Points
197 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Jan 21, 2013 09:58 PM|LINK
The picklist(s) is in support of a form. Half of my users come to the page with a promotion code in hand, and others just want to look up the promotion code. That's why the picklist is not part of the form.
If i can capture the picked values of theprimary list and also the secondary list into variables I can move forward.
actually I will populate the selected option into the donate text box.
Thanks
Dallas
Rion William...
All-Star
27716 Points
4574 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Jan 21, 2013 10:00 PM|LINK
Since you are most likely going to be submitting this anyways - a good idea may be to create a hidden field (or two) within your form and then when any of the drop-downs are changed you can update the values within your form accordingly.
By doing this, whenever you perform your submit you can check which values were selected :
<form> <!-- Your other fields in your form --> <input id='np_hidden' type='hidden' /> <input id='event_hidden' type='hidden' /> </form>along with this jQuery code :
$(document).ready(function(){ //When any of the drop-down boxes are changed, update the values accordingly $('select').change(function(){ $("#np_hidden").val($("#NpId").val()); $("#event_hidden").val($("#EventId").val()); }); });Example
saeed_saedva...
Member
408 Points
74 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Jan 23, 2013 06:52 PM|LINK
This articke can help you about your lists:
http://www.mikesdotnetting.com/Article/196/WebMatrix-jQuery-Cascading-Dropdown-Lists
Saeed Saedvand
asp.netforum...
Member
604 Points
132 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Jan 23, 2013 09:24 PM|LINK
Its may help for you
http://www.misfitgeek.com/2011/03/cascading-dropdown-with-jquery-webmatrix-version/#more-2800
DMT20601
Member
86 Points
197 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Feb 03, 2013 12:45 PM|LINK
I added two hidden fields to the list of fields in the form.
I built the function and saved it to it's own file CasCadingValue.js then added that to the scripts list on the page.
I can now populate the Donate field on the form by passing the EventId value from the pick list to the "donateId" when the value changes.
$('select').change(function () { $("#np_hidden").val($("#NpId").val()); $("#event_hidden").val($("#EventId").val()); $("#donate").val($("#EventId").val()); $("#donate").val($("Event.DonateCode?#EventId").val()); // This doesn't work.The question. (its a long question)
The value passed is the "Id" of the selected table entry, not the text value needed. Can I pull the text field value within this function (it's on the screen, I should be able to get to it) or do I need to point the function to another file "CasCadingValue.cshtml" and pass the selected Id to a database querysingle then take that result and populate a global variable then somehow get back to this calling page.
Thanks
Rion William...
All-Star
27716 Points
4574 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Feb 04, 2013 11:52 AM|LINK
Can you post some of your rendered markup? I can't tell exactly what you are trying to target with the following jQuery selector :
$("Event.DonateCode?#EventId").val();As the syntax within the selector looks like it might be incorrect. If you are trying to get the selected text within your #EventId drop-down, then you will want to use :
$("#EventId option:selected").text();DMT20601
Member
86 Points
197 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Feb 04, 2013 02:12 PM|LINK
This actually pulls the text from the string and populates the donate field. Wow.
Can you substring(1,8) the first 8 characters. Message: Object has no method Substring.
$("#donate").val($("#EventId option:selected").text().Substring(1,8));Rion William...
All-Star
27716 Points
4574 Posts
Re: Webmatrix - Pulling the result of a drop down list.
Feb 04, 2013 02:24 PM|LINK
The .substring() method in Javascript is all lowercase (unlike is C# counter-part):
$("#donate").val($("#EventId option:selected").text().substring(0,8));