[jQuery] jQuery + select
This is a little baffling to me. I can get the selected value (val attribute) on an option element, but only by using the following method: var selectedId = $(#mySelectElement :selected).val(); This is great, but all the examples I have read simply do the following: var selectedId = $(#mySelectElement).val(); Supposedly this returns the value stored in the val attribute, but every time I try it it returns the text instead. Am I doing something wrong? Thanks for your help! Matt
Re: [jQuery] jQuery + select
On Wed, Jan 20, 2010 at 12:34 AM, Mateo matthew.kim...@gmail.com wrote: var selectedId = $(#mySelectElement).val(); Returns the value of the select element but you want the value of the selected option element under the select, hence: var selectedId = $(#mySelectElement :selected).val(); Nathan
[jQuery] jQuery select where attribute ID less than
How can I do a less than in a select e.g. something like $.(span.class [id+ a_custom_variable +]) when I tried that it just selected all span of class with an ID attribute rather than where ID attribute is less than
[jQuery] [jQuery]Select Boxes - Pulling the currently selected string instead of value
How do I retrieve the currently selected option string in a select box instead of the value? select id=choices option value=valueString/option /select Using $(#choices).val(); returns the value if it's set. if there is no value set, jQuery returns the string instead. I want to retrieve the string while a value is set! Thanks for you time, I'm sure this something that I simply overlooked.
[jQuery] jQuery select all vs conventional javascript
Hi All, I have been using jQuery for quite some time now. For one of my projects, I needed to select all the options in the listbox which were 10,000+. I tried to do a comparison between using jQuery and conventional javascript and here are my findings: 1. With jQuery: Code: $(#myListBox *).attr(selected,selected); Time taken: 7+ milliseconds 2. With JavaScript: Code: for( i=0; i myListBox.length; i++) { myListBox [i].selected = true; } Time taken: 21000+ milliseconds Can anyone provide with some better code or justify why is jQuery taking so much time. Also is it possible for me to raise a SHIFT+END command anyhow..?
[jQuery] jQuery select option with errors for IE 6
Hi: It seems that the following code snippet works for IE 7 and FireFox but not for IE6: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http:// www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd html xmlns=http://www.w3.org/1999/xhtml; head title/title meta http-equiv=Content-Type content=text/html; charset=UTF-8 script type=text/javascript src=jquery-1.2.1.js/script script type=text/javascript $(document).ready(function() { $(a#clickme).click(function() { var $x = $(select#dept); $x.html(option value='0'Select.../option); $x.append(option value='1'First/option); $([EMAIL PROTECTED]'0'], $x).attr(selected,selected); }); }); /script /head body a id=clickme href=javascript:{}click here/a table tr td labelDepartment: /label /tdtd select id=dept name=dept tabindex=1 /select /td /tr /table /body /html On IE6, I am getting this error: Line: 867 Char: 30 Error: Could not set the selected property. Unspecified error. Code: 0 URL: http://localhost:8080/jQueryTutorial/select.html However, if I change the scriptlet to use direct DOM object as shown below, IE 6 is happy. $(document).ready(function() { $(a#clickme).click(function() { var $x = $(select#dept); var y = $x.get(0) y.options[0] = new Option; y.options[0].text = Select...; y.options[0].value = 0; y.options[0].selected = selected; y.options[1] = new Option; y.options[1].text = First; y.options[1].value = 1; }); }); Has anyone experienced the same issue? Thanks in advance.
[jQuery] jQuery + Select Box woes
Hi all, I'm having some difficulty getting select boxes to function the way I envision them to function. I'm using the Plugin available from: http://www.texotela.co.uk/code/jquery/select/ My code looks like the following: $(select#make).change(function() { $.ajax({ data: {make_val: $(this).val()}, dataType: 'json', timeout: 1, type: 'POST', url: /addvehicle/models_populate, error:function() {}, success: function(json) { json = eval(json); var options = ''; for (var i = 0; i json.length; i++) { options += 'option value=' + json[i]['name'].toLowerCase() + '' + json[i]['name'] + '/option'; } $(select#model option).not(.staticOpt).remove(); $(select#model).append(options); } // end callback funct(json) }); // end $.ajax }); // end $(select#make) // populate the trims select when model is changed. $(select#model).change(function() { $.ajax({ data: {model_val: $(this).val()}, dataType: 'json', timeout: 1, type: 'POST', url: /addvehicle/trims_populate, error:function() {}, success: function(json) { json = eval(json); var options = ''; for (var i = 0; i json.length; i++) { options += 'option value=' + json[i]['name'].toLowerCase() + '' + json[i]['name'] + '/option'; } if(json.length === 0) { $(select#trim).append('option value=no trimNo Trim/option'); $(select#trim).selectOptions(No Trim); } else { $(select#trim option).not(.staticOpt).remove(); $(select#trim).append(options); } } // end callback funct(json) }); // end $.ajax }); // end $(select#model) --- Essentially, what I'm trying to achieve is to populate a Model box based on a Make box. At the same time, I want to populate a Trim select box with No Trim if /addvehicle/trims_populate comes back with a zero length json object. What happens here though, if I change my 'Model' box, trims populate just -fine-. However, when I change my Make select, it populates the Trim boxes with different 'Models' where it should be populating it with Trims. I need to change a 'Model' again to populate it with the proper trims. I know it's rather confusing, and I appreciate it if anyone can give me any hints. Cheers all, - sf