[jQuery] Re: Select box change event infinite loop in ASP.NET

2007-05-24 Thread Roger Roelofs


Mike,

On May 22, 2007, at 1:17 PM, Mike Chabot wrote:


I have a simple function to capture the OnChange event of a drop-down
select box. In MSIE, it works as expected, but Firefox gets caught in
an infinite loop. Has anyone else seen this problem? I have a counter
to track the problem. In MSIE, the counter goes up by 1 for every
change. In Firefox, the counter jumps by 21 with every change. I guess
21 is some recursive limit inside of Firefox.

jQuery 1.1.2 and ASP.NET 2.0.

var count=0;
$(document).ready(function() {
  var selectBox = $%= Me.FormView1.ClientId %_ddlTestList;
  $(selectBox).change(
  function() {
count = count + 1;
$(#countId).text(count:  + count);
  }
  );
});


Are you using your scroll wheel or arrow keys to select from the  
menu?  I've noticed that ie doesn't fire the change event until you  
tab out of the select while firefox fires the onchange event every  
time you make a new selection (at least on my mac)  You can save  
yourself a lot of debugging time by using the firebug firefox extension.


hth

Roger,
--
Roger Roelofs
[EMAIL PROTECTED]





[jQuery] Re: alerting the value of radio button onfocus

2007-05-23 Thread Roger Roelofs


Stef,

On May 22, 2007, at 10:40 AM, stef wrote:


when a radio button is clicked, show its
value. i have the code below, which i dont think is the best way to go
about it. it always alerts undefined. my reasoning is: when the
document has loaded, and an input element in the div with id 'test' is
focussed, show an alert of the value of the currently checked radio
button.

 $(function(){
$(#test/input).focus( function() {
alert($([EMAIL PROTECTED]@checked]).value);});

 });


Having a url to a live page to debug would make it easier for us to  
help you.  A guess would be something like this...


$(function() {
  $(#test/[EMAIL PROTECTED]'radio']).bind(focus, function() {
if ( this.checked ) alert(this.value);
  });
});

--
Roger Roelofs





[jQuery] Re: show/hide revisited

2007-05-20 Thread Roger Roelofs


Schnuck,

On May 18, 2007, at 11:21 AM, Schnuck wrote:


i have this bit of code here (and god knows how old, unstylish and
inefficient the code below might be) and all i am trying is to make
one or two particular divs with set ids/classes to show and hide
triggered by a remote image somewhere else on the page. the image,
let's say a plus icon switches to a minus icon depending on the state
of the toggled divs. the example below at least does toggle between
shwo  hide but the div it should hide doesn't do anything. also, in
the example it uses text to display show or hide, this could be done
with images (like plus and minus)?


Maybe you have an answer already, but I didn't see one on the list.   
You can make the code simpler.  Something like this.


$(document).ready(function() {

$('.commenting').hide();

$('a.show_com').click(function() {
  if ( this.className == show_com ) {
$(.commenting).slideDown('slow');
$(this).removeClass(show_com).addClass(hide_com).text(HIDE  
COMMENTS);

  } else {
$(.commenting).slideUp('fast');
$(this).removeClass(hide_com).addClass(show_com).text(SHOW  
COMMENTS);

  }
  return false;
});
});

If you want a plus or minus you can either do it in test
$(this).removeClass(show_com).addClass(hide_com).text(-);
or you can add a background image in css

a.show_com, a.hide_com {
  width: 16px;
  height: 16px;
}

a.show_com {
  background-image: plus.gif;
}
a.hide_com {
  background-image: minus.gif;
}

The code could be even simpler if you use one class.

$('a.show_com').click(function() {
  $(this).toggleClass(show_com);
  $(.commenting).slideToggle(slow);
  return false;
});

then the css would be

a {
  width: 16px;
  height: 16px;
  background-image: minus.gif;
}

a.show_com {
  background-image: plus.gif;
}

--
Roger Roelofs