I'm trying to do some simple JavaScript in Rails but am having a lot of
difficulty getting it to work.
Basically, I have a form with a text field. When the user types in the
text field, I want to respond to each key press event and update another
field on the screen.
I want to do this *without* a round-trip to the server.
In straight HTML, it would look something like this:
Have you tried using another function name besides "test." Initially
this confused me too, but then I thought maybe "test" is a keyword in
JavaScript so I tried something else and it seems to work just fine.
function getStyle(answer) {
var styleField = document.getElementById('style');
styleField.innerHTML = answer
}
In the interests of DRY though, does anyone know how to pass in a
non-form variable to my javascript function so that I don't have to do
the document.getElementById lookup?
i.e.
getStyle($F('answer'), $P('otherElement'))
I guess I'm asking if there's a 'page' equivalent to the 'form'
shorthand "$F".