$.fn.addItems = function (data) {
return this.clearSelect().each(function () {
if (this.tagName == 'SELECT') {
var dropdownList = this;
$.each(data, function (index, optionData) {
var option = new Option(optionData.Text,
optionData.Value);
if ($.browser.msie) {
dropdownList.add(option);
}
else {
dropdownList.add(option, null);
}
if (dropdownList.childElementCount < 2) {
dropdownList.hide();
}
else {
dropdownList.show();
}
});
}
});
}
When running this is says : ropdownList.hide is not a function. It should not be that hard to hide an element, I have doned this before? I most be missing a vital part?
This is not resolved yet. I have also got another sugestion of solution where the call to the service will return a partialview of the dropdown. This might not be a bad idea. Im not sure how to accomplish this in detail.
Ok, I created another sample that use 4 dropdowns (Country, Region, City, Suburb). (Added it to the sample you can
download here)
The last 3 are hidden on load. One change, and the next one are loaded with data and shown.
If one in the chain are changed, those that are not required at the moment are cleared and hidden.
I can't put aside more time for this and hope you will investigate it further, but will update the sample in the future to come up with a re-usable bit of code.
name UserController inside of "Controllers" folder.
inside of that i create "FindProductsByColorID" function
but this function is not get called after we change ddl box value.
pls suggest me.
var url = "/UserController/FindProductsByColorID/" + color;
thanks,
prashant
Prashant
--------------------------------------------------
[Optional] If this reply is answer to your question then mark this reply as Answer
--------------------------------------------------
Prashant
--------------------------------------------------
[Optional] If this reply is answer to your question then mark this reply as Answer
--------------------------------------------------
i use the similar code for my cascade dropdown list.
my Jresult function in cotroller doing some complex job.. ( i already fine tune it).
based on that function my second and some other controls value get set...
now i want to show "busy" operation while this controller works in background...
hope you understand my point.
Prashant
--------------------------------------------------
[Optional] If this reply is answer to your question then mark this reply as Answer
--------------------------------------------------
krokonoster
Contributor
4291 Points
1352 Posts
Re: Cascading dropdown boxes and MVC2
Jun 13, 2010 09:52 AM|LINK
Moved that up into the code block above. You moved out of it, so do not have dropdownList anymore
SnowJim
Member
306 Points
293 Posts
Re: Cascading dropdown boxes and MVC2
Jun 13, 2010 10:06 AM|LINK
Hi,
this is how it looks :
$.fn.addItems = function (data) { return this.clearSelect().each(function () { if (this.tagName == 'SELECT') { var dropdownList = this; $.each(data, function (index, optionData) { var option = new Option(optionData.Text, optionData.Value); if ($.browser.msie) { dropdownList.add(option); } else { dropdownList.add(option, null); } if (dropdownList.childElementCount < 2) { dropdownList.hide(); } else { dropdownList.show(); } }); } }); }When running this is says : ropdownList.hide is not a function. It should not be that hard to hide an element, I have doned this before? I most be missing a vital part?
krokonoster
Contributor
4291 Points
1352 Posts
Re: Cascading dropdown boxes and MVC2
Jun 13, 2010 10:11 AM|LINK
yeah, sorry..must be missing something simple.
SnowJim
Member
306 Points
293 Posts
Re: Cascading dropdown boxes and MVC2
Jun 13, 2010 10:18 AM|LINK
Hehe no that do not help :
$.fn.addItems = function (data) { return this.clearSelect().each(function () { if (this.tagName == 'SELECT') { var dropdownList = this; $.each(data, function (index, optionData) { var option = new Option(optionData.Text, optionData.Value); if ($.browser.msie) { dropdownList.add(option); } else { dropdownList.add(option, null); } if ($(this).children().size() < 2) { $(this).hide(); } else { $(this).show(); } }); } }); }Now I get : elem.ownerDocument is undefined ( var defaultView = elem.ownerDocument.defaultView;)
I have checked that the $(this).children().size() returns the proper option count.
SnowJim
Member
306 Points
293 Posts
Re: Cascading dropdown boxes and MVC2
Jun 14, 2010 07:21 AM|LINK
Hi,
This is not resolved yet. I have also got another sugestion of solution where the call to the service will return a partialview of the dropdown. This might not be a bad idea. Im not sure how to accomplish this in detail.
What do you think?
BestRegards
krokonoster
Contributor
4291 Points
1352 Posts
Re: Cascading dropdown boxes and MVC2
Jun 14, 2010 11:04 AM|LINK
Ok, I created another sample that use 4 dropdowns (Country, Region, City, Suburb). (Added it to the sample you can download here)
The last 3 are hidden on load. One change, and the next one are loaded with data and shown.
If one in the chain are changed, those that are not required at the moment are cleared and hidden.
I can't put aside more time for this and hope you will investigate it further, but will update the sample in the future to come up with a re-usable bit of code.
I'm not too happy about the long script I got there, and asked for some expert advice in re-factoring where I know some real jQuery experts, eager to help are hanging around.
As for the other suggestion you were asking about, have a look how your original question changed. Try stick to one thread = one question.
mprashant_bi...
Member
29 Points
56 Posts
Re: Cascading dropdown boxes and MVC2
Jul 17, 2010 02:40 AM|LINK
i create a new controller
name UserController inside of "Controllers" folder.
inside of that i create "FindProductsByColorID" function
but this function is not get called after we change ddl box value.
pls suggest me.
var url = "/UserController/FindProductsByColorID/" + color;
thanks,
prashant
--------------------------------------------------
[Optional] If this reply is answer to your question then mark this reply as Answer
--------------------------------------------------
mprashant_bi...
Member
29 Points
56 Posts
Re: Cascading dropdown boxes and MVC2
Aug 03, 2010 03:25 AM|LINK
Very good post... like your approach..
thanks friend..
i have one quetion...
when i debug jason function in cotroller ...
that time ajax data is coming null...
this happens only i debug....
--------------------------------------------------
[Optional] If this reply is answer to your question then mark this reply as Answer
--------------------------------------------------
mprashant_bi...
Member
29 Points
56 Posts
Re: Cascading dropdown boxes and MVC2
Aug 03, 2010 09:13 AM|LINK
Hello mate,
i use the similar code for my cascade dropdown list.
my Jresult function in cotroller doing some complex job.. ( i already fine tune it).
based on that function my second and some other controls value get set...
now i want to show "busy" operation while this controller works in background...
hope you understand my point.
--------------------------------------------------
[Optional] If this reply is answer to your question then mark this reply as Answer
--------------------------------------------------