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.
alert($$('[name="td_website static"]')[0].value)
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With