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.
Related
Folks
We are creating the application and used the jquery as discussed in this website
we are using multiple select dropdown with checkboxes. ( as in the screenshot attached)
The issue is
we cannot update the return result of the ajax call.
eg
if i select the date to and date from then the result between these two dates should be filtered and should be displayed in the multiple select dropdown with checkboxes.
Let me know if there is any other way to implement the same.( multi select dropdown along with the checkbox functionality).
You want to use `$("select").multiselect('refresh');`
//create new object with ajax data
var opt = $('<option />', {
value: "new value",
text: "new text"
});
opt.appendTo(jqselect );
jqselect.multiselect('refresh');
I use the chosen (from jquery-chosen).
In chosen you can specify a filter, where you can use select with multi or not.
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/
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)
Im trying to find a tutorial or something that will allow me to populate 3 textboxes with data from a mysql database based on whats clicked on in a select dropdown box.
For example, my select looks like the following:
<select name="imaselect">
<option value="USA">USA</option>
<option value="AUS">AUS</option>
<option value="NZ">NZ</option>
</select>
Then under that i have 3 blank textboxes.
If i click USA, it will go to the database, ask for 3 values, return them and then put them in the 3 text boxes, same if i click AUS and the same if i click NZ.
Any help would be greatly appreciated, im having trouble with this.
Cheers,
You need 2 things.
a php file that connects to the database and retrieve the three values for the country passed to it as a parameter.
a javascript script that calls the php file with country name and puts the returned values in the textboxes.
<script type="text/javascript">
jQuery(function( $ ){
$("select").change(function(e) {
$(".temp").load(\'index.php?parameter1=\'+ $(this).val(), , function() {
$(".textbox1").val($(".temp1").text());
});
});
});
</script>
Something like this. Of course you have to set a reference to the jquery file. And then you have an index.php (or name it different) and can give it parameters however you want via the load function. The element with the class temp will get the content, because you cant use the load to get data in the textbox directly. (So you need to create that element .. hidden!) Then it gets copied into the element with the class textbox1. copy the 2 inner lines as many times as you want (just use like textbox2 instead, temp can stay the same)
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.