How to handle default dropdown values using jquery ajax in mvc3? - asp.net-mvc

Based on selection of first dropdown i am binding another drop down values based on first dropdownid value.My question is i given default first dropdown value as "select" but there is no id value for that in second dropdown to get the values.if user selectes "select" in frist dropdown i need to load all values in second dropdown.please tell me how to acheive this?

If you given default first dropdown value as "select" means, at that time disable the second drop down value. If 'country' value equal to 'select' means, at that time disable the 'state drop down'.When we click that country 'select' at that time also call that disable drop down function.
For example HTML view page, country drop down displayed. From that you will get country ID.
$countryID=> From your MVC code you have pass default country ID (default ID)
$countrySelected=$this->getCountryFromName(trim($countryID']));
if ($countrySelected!= ''){
$sVal=$this->getStateList($countrySelected);
$newStateList=array('0'=>'State');
$newStateList+=$this->formatDropdownArray($sVal,'STATE_ID','NAME');
$stateSelected='State';
echo CHtml::dropDownList('STATE_IDD',$stateSelected,$newStateList,array('tabindex'=>9));
}else{
$stateSelected=$defaultState;
echo CHtml::dropDownList('STATE_IDD',$stateSelected,$stateList,array('tabindex'=>9));
}

Related

sj:select tag in struts2-jquery plugin calls the JSON method again when the page gets submitted for a different action

This question is on Struts2 jquery plugin. While loading a JSP be default I am loading one dropdown list values and the second dropdown values are loaded based on selection of first dropdown. When the second dropdown value is selected an onChange event get executed and the page is getting refreshed. When the page is refreshing the First dropdown is getting called again! Is there anyway to avoid the second time execution of default loading of firstdropdown and also need to hold the selected values for both the submitted dropdown values of the JSP?
Note: First dropdown and second dropdowns are evaluated in SampleAction.java and onChange event executes LoadAction.java
Please let me know if you require further details!
Thanks
An option from the first dropdown is selected
Second dropdown is filled accordingly and then a value is selected
Instead of page-refresh, you can submit a form passing the values of both select tags
Now you get the selected values in your action and then you can show the same page but with prefilled values. This time when the page loads, the first select box by default shows the same previously selected value.
For the second select to show the previously selected value, you'll have to write some javascript code which will select the previously selected value.

Kendo-UI DropDownListFor - selected index

I need to change standard dropdown list to the one from kendo and and I've got a problem with getting appropriate selected value.
This code gives me a dropdown list with correct values, but doesn't give selected value (first one is selected).
#(Html.Kendo().DropDownListFor(m => m.CountryName)
.BindTo(Model.AllCountries)
.OptionLabel("-- Select country --")
)
Inside span (generated by kendo) with this dropdown I found input (type = text) with all values as options, and this input has correct value.
How to display this value in my kendo dropdown?
Thanks
Have you tried setting the name of the DropDownList equal to the name of the property in your model? The Kendo Documentation suggests that "if widget's name is different than the Model's property then the ModelBinder will not be able to update the model."

how to populate values in listbox based on value entered in textbox in BIRT?

I want to populate values in a list box based on a value entered in textbox. It cant be aceived through cascading paramters as all parameters in Cascading parameters are List Boxes. But my requirement is to populate values inside a ListBox based on the value entered inside a textbox. Please help.
Cascading parameter is the only way to define a dependency between two parameters. As you can see, the birt web viewer displays a textbox just below each combobox, and a radio button to select if we fill each list parameter from the combobox or the textbox:
I know some users had exactly the same requirement, and have successfully modified "ComboBoxParametersFragments.jsp" to display only the textbox when it is needed. For example we can use a specific prefix in the parameter name, or a user property, so that we can decide in the JSP if we hide the combobox or not.

Select from drop down menu or add another

I'm using simple_form. How can I have a select menu and a text input and have something like Select or add another.
The app will only take one value, either from the select menu or the text input.
It would also be good to validate to have either one or the other but not both, to avoid user confusion.
Implement what is called a 'combobox' to your simple_form
Jquery UI has a combobox:
http://jqueryui.com/autocomplete/#combobox
something fancier:
http://demos.kendoui.com/web/combobox/index.html
This will get you as far as your combo boxes displaying. I don't think there is a plugin for validating, so you'll have to write the code yourself.
You can try to use a combination of JavaScript and Ruby to solve this. If a user wants to enter a different value then what's available in the dropdown, you should have JS listen to a keydown event in that input and clear the dropdown, i.e.:
$(".input_field").bind('keydown', function() {
$(".select_field").val('0') // this should be a default blank value
});
That will clear the select when a user types. Likewise, you want to clear the input when the user selects from the dropdown, right?
$(".select_field").change(function() {
// Let's only clear the input field if the value is not the default null value
if ( $(this).val() != 0 ) {
$(".input_field").val('');
}
});
This will handle the front-end interactions. In the controller, you'll want to do some additional logic:
def create
object.new(...)
if params[:select] and params[:input]
# Overwrite the select with the input value
object.attribute = params[:input]
end
object.save
end
I assume that you want the input value to supersede the select, therefore if they are most submitted, we can just overwrite the select value with the input value and then continue to save the object.
Is this what you're looking for? Not sure if the inputted value was suppose to create a new object with a relationship or not. Hope this helps.

MVC - DropDownList wrong option selected when value from model is null

I have two DropDownLists in form, both displaying list of regions. First is required, second not, stored as null in db.
When I open the page for edit and first dropdownlist is ie. Region 2, and the second is null, the first option "< not specified >" should be selected in second dropdownlist, but the same option as in first dropdownlist is selected.
When I check for null in controller and set the property to value, which is not in the dropdownlist, ie. -1, it selects corrects first option "< not specified >".
Is there a way to recieve the first option selected, when the model value for this dropdown is null ?
kubiix

Resources