Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Get input value with Prototype?

Tags:

prototypejs

I have the following input without any form around it:

<input type="text" value="myValue" name="td_website static" class="td_inner_input">

How can I get the Input value with prototype? I tried to use alert($('tb_website static').value);, but it doesn't work.

like image 571
3logy Avatar asked Mar 08 '11 13:03

3logy


3 Answers

alert($$('[name="td_website static"]')[0].value)
like image 152
Jaroslav Jandek Avatar answered Dec 11 '22 09:12

Jaroslav Jandek


You need to use the $$ function which returns an array. There are a couple of ways to use an enumerable result.

If you know there will be only one matching element then use this:

$$('[name="tb_website static"]').first().value

If there are more than one input (which is valid HTML) then this gets an array of values:

$$('[name="tb_website static"]').map(Form.Element.getValue)

(By mapping through Form.Element.getValue - aliased as $F - it better handles browser differences and non-input elements that don't store their value in a value attribute)

like image 28
clockworkgeek Avatar answered Dec 11 '22 08:12

clockworkgeek


I'm pretty sure that $('tb_website static') will be looking for an element with that ID not that NAME.

Have another look at the PrototypeJS Documentation.

like image 35
Lazarus Avatar answered Dec 11 '22 08:12

Lazarus