[jQuery] Re: Selectbox
Actually found what I was looking for, it is here. http://blog.kotowicz.net/2009/03/jquery-optiontree-demo.html Thanks On Sep 15, 8:50 am, Richard Walsh rwa...@datagroup.ca wrote: I remember seeing a sample somewhere, now for the life of me when I actually need to use it. I can't remember how or where I found it. I am hoping someone can shed some light. What I want to achieve, is when a value is picked in a select box, an empty input field appears after a value is selected. If someone can point me in the right direction it would be great! Thanks
[jQuery] Re: Selectbox Manipulation...Works in FF but not in IE6 or IE7
I just realized I may need to explain a little further. I've got a table on the same page. Clicking on a record in that table populates a small form on the page with the information from that record. The text and check boxes are easy enough to populate, but telling the select box which of it's options is now selected as a result of that user click is a little harder it seems. The code snippet in my original post fires when a user clicks on a record in the table, and in FireFox 3.0.6 it works just fine, but in IE6 and IE7 it fails. I should also probably mention that I'm using jquery 1.2.6 packed. Thanks, Chris On Feb 26, 3:11 pm, Chris Jordan chris.s.jor...@gmail.com wrote: Hi folks, I'm trying to manipulate which item in a select box is selected using jQuery. The following code snippet works great in FF but fails miserably in IE6 and IE7 // select the publish to option $(#PublishToID option).each(function(){ $this = $(this); if($this.attr(textContent) == PublishTo){ $this.attr(selected, true) } }); Given that I have a select box that looks like this: select name=PublishTo id=PublishToID option value=3Some Page Title/option option value=4Some Other Page Title/option option value=5Page 5/option option value=1Page 1/option option value=2Page 2/option /select --http://cjordan.us
[jQuery] Re: Selectbox Manipulation...Works in FF but not in IE6 or IE7
I'm not sure about the: if($this.attr(textContent) == PublishTo) part. It sounds very custom. Provided this conditional check is working correctly, how about trying: $this.attr(selected, selected) ; to set the value. Or if you can get the actual options value, you can set the value of the select drop-down: $(select).val(1); On Feb 26, 11:24 am, Chris Jordan chris.s.jor...@gmail.com wrote: I just realized I may need to explain a little further. I've got a table on the same page. Clicking on a record in that table populates a small form on the page with the information from that record. The text and check boxes are easy enough to populate, but telling the select box which of it's options is now selected as a result of that user click is a little harder it seems. The code snippet in my original post fires when a user clicks on a record in the table, and in FireFox 3.0.6 it works just fine, but in IE6 and IE7 it fails. I should also probably mention that I'm using jquery 1.2.6 packed. Thanks, Chris On Feb 26, 3:11 pm, Chris Jordan chris.s.jor...@gmail.com wrote: Hi folks, I'm trying to manipulate which item in a select box is selected using jQuery. The following code snippet works great in FF but fails miserably in IE6 and IE7 // select the publish to option $(#PublishToID option).each(function(){ $this = $(this); if($this.attr(textContent) == PublishTo){ $this.attr(selected, true) } }); Given that I have a select box that looks like this: select name=PublishTo id=PublishToID option value=3Some Page Title/option option value=4Some Other Page Title/option option value=5Page 5/option option value=1Page 1/option option value=2Page 2/option /select --http://cjordan.us
[jQuery] Re: Selectbox Manipulation...Works in FF but not in IE6 or IE7
James, Thanks for the response. I don't know why I didn't see it before, but your comment about the conditional check got me thinking. I did try $this.attr(selected, selected); and that works just as well as my original, but the conditional is where my problem was. FF understood the 'textContent' attribute, but IE67 only understood 'text'. Honestly, when I was looking at the thing originally in FF, I just didn't see 'text' I saw only 'textContent' so that's what I used. Thankfully though FF and IE67 understand $this.attr(text), so I'm all good now. Thanks, Chris On Feb 26, 3:32 pm, James james.gp@gmail.com wrote: I'm not sure about the: if($this.attr(textContent) == PublishTo) part. It sounds very custom. Provided this conditional check is working correctly, how about trying: $this.attr(selected, selected) ; to set the value. Or if you can get the actual options value, you can set the value of the select drop-down: $(select).val(1); On Feb 26, 11:24 am, Chris Jordan chris.s.jor...@gmail.com wrote: I just realized I may need to explain a little further. I've got a table on the same page. Clicking on a record in that table populates a small form on the page with the information from that record. The text and check boxes are easy enough to populate, but telling the select box which of it's options is now selected as a result of that user click is a little harder it seems. The code snippet in my original post fires when a user clicks on a record in the table, and in FireFox 3.0.6 it works just fine, but in IE6 and IE7 it fails. I should also probably mention that I'm using jquery 1.2.6 packed. Thanks, Chris On Feb 26, 3:11 pm, Chris Jordan chris.s.jor...@gmail.com wrote: Hi folks, I'm trying to manipulate which item in a select box is selected using jQuery. The following code snippet works great in FF but fails miserably in IE6 and IE7 // select the publish to option $(#PublishToID option).each(function(){ $this = $(this); if($this.attr(textContent) == PublishTo){ $this.attr(selected, true) } }); Given that I have a select box that looks like this: select name=PublishTo id=PublishToID option value=3Some Page Title/option option value=4Some Other Page Title/option option value=5Page 5/option option value=1Page 1/option option value=2Page 2/option /select --http://cjordan.us
[jQuery] Re: selectbox event problem in MSIE
Thanks a lot for your answers! My solution with a bit of jQuery magic looks like this: $(#wgt2 ).change(function() { $(this).children(option:selected).each(function() { var selectValue = $(this).val(); var selectText = $(this).text(); $(this).removeAttr('selected'); alert(Text: + selectText + / Value: + selectValue); }); }); This works with IE and Firefox as expected. Now IE annoys me by handling the next step, but this is resolvable. ;-) Kind regards, Ralf
[jQuery] Re: selectbox: change selected item
zenx wrote: Hi, I don't know how to change the selected item in a selectbox. I tried this but it doesn't work as expected. HTML code: = select id=id_cliente name=cliente size=1 option value= selected=selected-/option option value=1First/option option value=2Second/option /select javascript code: var cliente = 2; $('#id_cliente:nth-child(cliente)').attr('selected','selected'); any ideas? Thank you! Try: var cliente = 2; $('#id_cliente').val(cliente); --Klaus
[jQuery] Re: selectbox: change selected item
I don't know how to change the selected item in a selectbox. I tried this but it doesn't work as expected. HTML code: = select id=id_cliente name=cliente size=1 option value= selected=selected-/option option value=1First/option option value=2Second/option /select javascript code: var cliente = 2; $('#id_cliente:nth-child(cliente)').attr('selected','selected'); any ideas? Using my Field plug-in (http://jquery.com/plugins/project/field) you could do: $(#id_cliente).setValue(2); The big benefit to using my Field plug-in is that you can change the form field from a select box to a checkbox or radio element and you would not have to refactor code that grabs/sets the value of the field. -Dan
[jQuery] Re: selectbox: change selected item
Dan G. Switzer, II wrote: I don't know how to change the selected item in a selectbox. I tried this but it doesn't work as expected. HTML code: = select id=id_cliente name=cliente size=1 option value= selected=selected-/option option value=1First/option option value=2Second/option /select javascript code: var cliente = 2; $('#id_cliente:nth-child(cliente)').attr('selected','selected'); any ideas? Using my Field plug-in (http://jquery.com/plugins/project/field) you could do: $(#id_cliente).setValue(2); The big benefit to using my Field plug-in is that you can change the form field from a select box to a checkbox or radio element and you would not have to refactor code that grabs/sets the value of the field. -Dan Dan, that truly is an advantage. But I was of the opinion, that val() works with selects and radios as well, thus the refactoring possibility exists for core jQuery as well (of course I don't want people to stay away from your plugin by saying that). Another question (Mike, Dan?). What are the differences between form and field plugin? --Klaus
[jQuery] Re: selectbox: change selected item
Using my Field plug-in (http://jquery.com/plugins/project/field) you could do: $(#id_cliente).setValue(2); The big benefit to using my Field plug-in is that you can change the form field from a select box to a checkbox or radio element and you would not have to refactor code that grabs/sets the value of the field. -Dan Dan, that truly is an advantage. But I was of the opinion, that val() works with selects and radios as well, thus the refactoring possibility exists for core jQuery as well (of course I don't want people to stay away from your plugin by saying that). I don't believe val() is 100% cross-browser compatible for select elements. val: function( val ) { return val == undefined ? ( this.length ? this[0].value : null ) : this.attr( value, val ); }, The code only works if the element returns a value attribute. This might work in most modern browsers for a select-one element, I'm not sure what the behavior is for a select-multi element. Also, my getValue()/setValue() methods work with checkbox and radio elements (well, every field element--the only exception being the setValue() on read-only elements.) Another question (Mike, Dan?). What are the differences between form and field plugin? The Field plug-in is basically a companion/stand-alone to the Form plug-in. You don't need Mike's Form plug-in, but it works great in conjunction with Mike's code. My plug-in is geared towards reading and manipulating the form fields themselves. Methods such as the formHash() make it really easy to populate a form based upon a JSON packet. It's also the first jQuery plug-in that allowed both getting and setting the value for all form field elements. I'm also working on adding addition useful form-based UI methods. I just recently added limitSelection() (allows you to limit the number of checkbox/select elements that can be selected) and createCheckboxRange() (allows you to [SHIFT]+click to highlight a range of checkbox elements.) -Dan
[jQuery] Re: selectbox: change selected item
Klaus, As Dan pointed out, his Field plugin is very adept at getting, setting and otherwise manipulating data for field elements and Dan is adding new capabilities regularly. The Form plugin is mostly geared at providing ajax capabilities for the submit process. It also provides methods for getting and serializing field values, but there is no complementary setting or deserialization capabilities at this time. Mike On 7/17/07, Dan G. Switzer, II [EMAIL PROTECTED] wrote: Using my Field plug-in (http://jquery.com/plugins/project/field) you could do: $(#id_cliente).setValue(2); The big benefit to using my Field plug-in is that you can change the form field from a select box to a checkbox or radio element and you would not have to refactor code that grabs/sets the value of the field. -Dan Dan, that truly is an advantage. But I was of the opinion, that val() works with selects and radios as well, thus the refactoring possibility exists for core jQuery as well (of course I don't want people to stay away from your plugin by saying that). I don't believe val() is 100% cross-browser compatible for select elements. val: function( val ) { return val == undefined ? ( this.length ? this[0].value : null ) : this.attr( value, val ); }, The code only works if the element returns a value attribute. This might work in most modern browsers for a select-one element, I'm not sure what the behavior is for a select-multi element. Also, my getValue()/setValue() methods work with checkbox and radio elements (well, every field element--the only exception being the setValue() on read-only elements.) Another question (Mike, Dan?). What are the differences between form and field plugin? The Field plug-in is basically a companion/stand-alone to the Form plug-in. You don't need Mike's Form plug-in, but it works great in conjunction with Mike's code. My plug-in is geared towards reading and manipulating the form fields themselves. Methods such as the formHash() make it really easy to populate a form based upon a JSON packet. It's also the first jQuery plug-in that allowed both getting and setting the value for all form field elements. I'm also working on adding addition useful form-based UI methods. I just recently added limitSelection() (allows you to limit the number of checkbox/select elements that can be selected) and createCheckboxRange() (allows you to [SHIFT]+click to highlight a range of checkbox elements.) -Dan
[jQuery] Re: selectbox: change selected item
Mike Alsup wrote: Klaus, As Dan pointed out, his Field plugin is very adept at getting, setting and otherwise manipulating data for field elements and Dan is adding new capabilities regularly. The Form plugin is mostly geared at providing ajax capabilities for the submit process. It also provides methods for getting and serializing field values, but there is no complementary setting or deserialization capabilities at this time. Mike Thanks for clarification! Sounds like a good candidate to me to being merged?! --Klaus
[jQuery] Re: selectbox: change selected item
Klaus, Dan, thank you for your help. I tried both ways and they worked correctly. I think I will use the Field plugin for many things in the future. Thank you! On 17 jul, 18:37, Klaus Hartl [EMAIL PROTECTED] wrote: Mike Alsup wrote: Klaus, As Dan pointed out, his Field plugin is very adept at getting, setting and otherwise manipulating data for field elements and Dan is adding new capabilities regularly. The Form plugin is mostly geared at providing ajax capabilities for the submit process. It also provides methods for getting and serializing field values, but there is no complementary setting or deserialization capabilities at this time. Mike Thanks for clarification! Sounds like a good candidate to me to being merged?! --Klaus