[jQuery] Re: Jquery 1.2.3 does not return a type for radio controls?

2009-01-14 Thread Scott Sharkey


Karl Swedberg wrote:
hmm. that doesn't sound right to me. I just put up a test page using 
jQuery 1.2.3, and it identified radio controls just fine:


http://test.learningjquery.com/123.html

Can we see the HTML? Maybe something else is going on.


div id=job_template
fieldset
label for=jt_textfield id=jt_textfield_labelText/label
input type=text name=jt_textfield id=jt_textfield size=30
br /
input type=checkbox name=jt_check1 id=jt_check1This is checkbox 1
br /
input type=checkbox name=jt_check2 id=jt_check2This is checkbox 2
br /
label for=jt_textfield2 id=jt_textfield2_labelSecond Text/label
input type=text name=jt_textfield2 id=jt_textfield2 size=30
/fieldset
table
  tbody
tr
  tdinput name=jt_dist_r_lo value=NY type=radioNY/td
  tdinput name=jt_dist_r_lo value=OH type=radioOH/td
  tdinput name=jt_dist_r_lo value=PA type=radioPA/td
/tr
  /tbody
/table
textarea name=jt_textarea id=jt_textarea rows=2 cols=20
/textarea
/div

Same problem with the textarea, by the way.

Here's the javascript...  (note, this is from a genshi template - 
${job.description} is a url string that encodes the names of the 
controls and their values, like so:


jt_textfield=this%20is%20textjt_checkbox1=onjt_dist_r_lo=OHjt_textarea=this%20is%20a%20textarea 




var jt_values = ${job.description};
var els = jt_values.split('amp;');
$.each(els, function() {
var items = this.split(=);
var item = # + items[0];
var item_val = decodeURIComponent(items[1]);

switch ( $(item).attr('type') ) {
case 'radio': alert(item +  is radio);
break;
case 'checkbox': $(item).attr(checked,checked);
break;
case 'text': $(item).val(item_val);
break;
case 'textarea': $(item).val(item_val);
alert(item +  is textarea =  + item_val);
break;
default:
alert(item+'unknown type:'+$(item).attr('type'));
}

I'm getting undefined in the alert for unknown type on both jt_dist_r_lo
and jt_textarea


[jQuery] Re: Jquery 1.2.3 does not return a type for radio controls?

2009-01-13 Thread Miloš Rašić
I have no idea if there is a bug like that, but I use this kind of
construction to determine if an element is something I need it to be:
if ($('#element_id:radio').attr('id')=='element_id')

You can use many other : selectors to check if an element is something like
an input of a type or visible or animated, etc. I really wish there were
some jQuery functions for this. I don't see a better cross-browser way to do
this. Just selecting a non-existing element will return an Object just like
an existing element. .attr('id') on a non-existing element will return
'undefined' on some browsers and 'null' on others.

On Tue, Jan 13, 2009 at 9:15 PM, Scott Sharkey
sshar...@linuxunlimited.comwrote:


 Hi All,

 I'm stuck with Jquery 1.2.3 in a trac-based application.  I'm trying to get
 the type of a form control, to determine what mechanism I should use to set
 it's value (ie, text controls use .val(), checkboxes get .attr(checked,
 checked) etc.).  When I fetch my list of controls, and loop through them
 with each, printing the value of .attr('type') on each... the text,
 checkbox, and textarea types work fine, but radio controls come up
 undefined. Is this a jquery bug?  Does anyone know if/when it was fixed?
  Maybe I can port that patch back to 1.2.3 to solve my problem.

 Any other suggestions appreciated.

 -Scott



[jQuery] Re: Jquery 1.2.3 does not return a type for radio controls?

2009-01-13 Thread Karl Swedberg
hmm. that doesn't sound right to me. I just put up a test page using  
jQuery 1.2.3, and it identified radio controls just fine:


http://test.learningjquery.com/123.html

Can we see the HTML? Maybe something else is going on.

--Karl


Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Jan 13, 2009, at 3:15 PM, Scott Sharkey wrote:



Hi All,

I'm stuck with Jquery 1.2.3 in a trac-based application.  I'm trying  
to get the type of a form control, to determine what mechanism I  
should use to set it's value (ie, text controls use .val(),  
checkboxes get .attr(checked, checked) etc.).  When I fetch my  
list of controls, and loop through them with each, printing the  
value of .attr('type') on each... the text, checkbox, and textarea  
types work fine, but radio controls come up undefined. Is this a  
jquery bug?  Does anyone know if/when it was fixed?  Maybe I can  
port that patch back to 1.2.3 to solve my problem.


Any other suggestions appreciated.

-Scott