I get the script for selecting the previous selected value in list box from Jquery get the pervious selected value in listbox
It is fine for the individual select boxes.
I have multiple select boxes. I wrote the change event with the class name. It returns undefined. Please refer this fiddle
http://jsfiddle.net/uW2ND/1/
How can i get the previous selected value of the each selected list box with this.
You forgot to include the code that actually sets the value of the jQuery-data to the previous value!
Check out this solution: http://jsfiddle.net/uW2ND/2/
This fiddle illustrates the proper way to persist the previous value. More specifically, it stores each select box's previous value in its related data() container. The first time around it would not alert anything, since no previous value is set.
http://jsfiddle.net/KxEKd/1/
Related
I have added 5 drop down fields in my form with the same name. These field will be displayed based on selected country's radio button.I have 5 radio buttons named as "USA,INDIA,UK,EURO,AUS".
If i select USA, 1st drop down contains US sizes, will be displayed.
If i select INDIA,2nd drop down contains INDIAN sizes, will be displayed.
All are working Good. Now i have an issue with store that value to my DB in magento. When i submit the form, 5th drop down field(EURO sizes) value only saved.
If i select size other than EURO,I got an empty value. If i select Euro size, I got correct value.I hope you understand my problem. Please guide me to solve mine issue guys!
You can add disabled attribute to other drop-downs when you show the selected one. This way the browser will ignore the disabled ones.
Or, you could append [] to your drop-downs' name, like this:
<select name="name[]"> ... </select>
This way you will get an array in the request variable, then you can decide which to use in the array according to your radio button value.
I am working on multiselect group. Here is the link i have populated some data in the multiselect group and the users can select their requirements in that.
http://vignesh.gvignesh.org/chose/chose.php
Here once show selected button is clicked i am calling javascript function.
function chos()
{
var a = $(".chzn-select").chosen();
alert(a);
}
it is not showing the selected values in alert box. Some [object][object] is displayed.
i dont know how to get the selected values. If my javascript function for getting the values is wrong kindly let me know the new function.
Thanks in Advance.
Just use $("#chossen").val(), which returns an array of values that are currently selected.
To get the actual option elements that are selected, try $("#chossen").find("option:selected");, and then loop through those (obviously) - in case you want to get their text.
I have 6 select boxes (sbs), 3 to a row so two rows. The top three sbs contain a list of options that gets populated via php, data is pulled back from mysql. When an option from each box is selected I'm using jquery (via ajax) to pull back option items for the sb immediately below it and populate said sb with corresponding data. I click 'create' and the data is sent via ajax to a php script which then stores the data in a table and returns the submited dropdown data (albeit formatted) in a table below the form. So you might have something that looks like this after creating a 'combination'. Eveyrthying to the left of the colon was an option on the top row of select boxes and then you have selected options from the corresponding box below displayed to the right.
Color: Red | Capacity : 4GB | Model : ABC | EDIT
Color: Blue | Speed: 2GHZ | Capacity : 2GB | EDIT
etc.
If I want to edit the record I click edit and jquery finds the id of the edit button clicked, passes it via ajax to another php script which then returns a json object with the relevant data and this is then used to repopulate the dropdown boxes with the selected options. Everything so far works fine.
My problem is this, only the top row of sbs get one of the options selected when edit is clicked. The child options don't get selected and I can't figure out why. I can get the right options to display but can't set the selected state for whatever matching value is returned in my json object. I've been 8 hours trying to figure it out and tried various things on SOverflow and other sites, none of worked - i'm not that experienced with javascript/ajax to be honest.
Upon a successful ajax process i.e success: I am doing the following:
var jObj = $.parseJSON(html);
//parentVariations# is the select boxes in the top row where
//Color, capacity, model options are displayed.
//The trigger fires off my ajax function which is responsible for
//populating the corresponding child select box with relevant data.
$('#parentVariations1').val(jObj.groupAttr1).trigger('change');
$('#parentVariations2').val(jObj.groupAttr2).trigger('change');
$('#parentVariations3').val(jObj.groupAttr3).trigger('change');
//childVariations# is the child option box, i have the same code for each child
//box but am only showing the first one here for simplicitys sake.
//What I thought I was doing here is getting each option then if the value
//matches that held in my corresponding json object set that option to selected...
//Doesn't work :'(
$("#childVariations1 option").each(function()
{
if($(this).val() == jObj.childAttr1)
{
$("#childVariations1 option").attr('selected','selected');
}
});
Any help would be very welcome as it's driven me over the edge.
$("#childVariations1 option") is an array of all the options. You need to specify which one:
$("#childVariations1 option").eq(1).attr('selected','selected');
If your case, use a for loop and use the index for get the current position, instead of using .each. (or set up a counter)
I am new to php, i have some problem in php page. This page contain one while loop, in that loop itself taking record from data base, it showing taxt box, list box like this,,,etc..Here php page while loop contain more then 5 records. here i need to select list box value to pass post to set session in next page. From that session i have take value to show next php page.
So here which type array i have to use,...and using get am going to pass value ,,,but value is 0 coming without selecting value,,..if am select list box value it ll come null value,,please suggest how can i pass whole value to next page,...
thanks
periyasamy
Insert the contents of the data from the previous page into the form that posts to the next page, in the form of <input type="hidden" name="foo" value="bar" />. Then, pull it out of the $_POST array on the next page.
About the <select> element returning NULLs, try specifying the name attribute on the <select> element, and a value attribute on each of the <option> elements. Don't forget to have one with the selected="selected" attribute set, to specify a default.
Hi i am using dropdown for display the timezone.The timezone values are come from database.Whenever the user change the value I need to alert the new timezone.For example if user change the time GMT+5.30 to GMT+6.30 then I want to alert GMT+6.30.Here the the dropdown values coming as an array?What can I do to get the values?
If you're using select and you have set values for your options, you can:
$("select#dropdown").change(function(){
alert($(this).val());
});
To do this, you need the jQuery framework. http://www.jquery.com/
checkout http://www.texotela.co.uk/code/jquery/select/ plugin for handling select element, very handy.