# JS Form Validation

**URL:** <https://www.ruby-forum.com/t/js-form-validation/105803>\
**Category:** Rails\
**Created:** [June 3, 2007, 2:57am UTC](https://www.ruby-forum.com/t/js-form-validation/105803 "2007-06-03T02:57:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [June 3, 2007, 2:57am UTC](https://www.ruby-forum.com/t/js-form-validation/105803/1 "2007-06-03T02:57:01Z")

</div>

Suppose that I use Rails to create an HTML form element.  
By that I mean that I have some Ruby code that I call from  
within \<%= %\> and the Ruby code then generates the form  
element for me. So what actually gets stuck into the code  
might look like this:

It appears that if, on submission, I use JS to validate by checking  
to see if element1 is longer than 0 characters, it appears that  
JS thinks that element1 is undefined. Am I making some mistake;  
or, is that the expected result? If it is the expected result,  
anything  
I can do so as to be able to validate using JS?

Thanks.

```
   ... doug
```

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [June 3, 2007, 3:50am UTC](https://www.ruby-forum.com/t/js-form-validation/105803/2 "2007-06-03T03:50:04Z")

</div>

On Jun 2, 2007, at 6:55 PM, doug wrote:

> It appears that if, on submission, I use JS to validate by checking  
> to see if element1 is longer than 0 characters, it appears that  
> JS thinks that element1 is undefined.

You’ll need an id=“element1” in there for getElementById to work.
