Tag Archives: Prototypejs

Checking radiobuttons with Prototype

example:
<input type='radio' name='test' value='1' />
<input type='radio' name='test' id='nr2' value='2' />
<input type='radio' name='test' value='3' />

$$("input[type=radio][name='test'][value='3']")[0].writeAttribute("checked", "checked");
or
$("nr2").writeAttribute("checked", "checked");

Related Blogs

Prototype stripTags

Prototype’s stripTags function needs a string as input. If you want to access a dom node with this function, you need to acces the innerHTML, else the input won’t match.

expl.

alert($(‘mydiv’).stripTags(); -> wont work
use

alert($(‘mydiv’).innerHTML.stripTags();

Related Blogs

  • Related Blogs on Prototypejs
  • Related Blogs on striptags()

Copy to clipboard with Prototype

Joe Gornick wrote a Prototype extension that lets users copy data to the clipboard.
The code uses javascript in Internet Explorer and some flash for other browsers.
Check it out at Joe Gornick’s site.

Prototype css selectors and observe

When using $$ in Prototype, the result is an array. You need to loop through the array to attach the observe function. Expl.
$$(‘.myitems‘).each(function(item) { item.observe(‘click’,function(){alert (‘clicked’)});});

or

$$(‘.myitems’).invoke(‘observe’, ‘click’, function() {alert(‘clicked’)});

Fire events with Prototype

It’s not possible to fire the default events with Prototype 1.6. Only custom events are supported.

$(‘mybutton’).observe(‘click’,function(){…});
$(‘mybutton’).fire(‘click’); will not work

$(‘myinput’).observe(‘input:changed’,function(){….});
$(‘myinput’).fire(‘input:changed’); does work

Checkboxes in Prototype

observing:
$(‘mycheckbox’).observe(‘click’, function(e){alert(‘checked = ‘ + this.checked);});

setting throught scripting:
$(‘mycheckbox’).checked = true;
$(‘mycheckbox’).setAttribute(‘checked’, true);
$(‘mycheckbox’).setValue(”); // will un-check/null value
$(‘mycheckbox’).setValue(‘anything’); // will check/on value
$(‘mycheckbox’).click(); // will toggle the checkbox