Forum: Ruby Basic Question on passing value to Javascript

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
60dcd839c644903a086c33b447343a1f?d=identicon&s=25 Adarsh M. (adarsh12in)
on 2014-06-18 07:29

I am fairly new to Ruby (& Sinatra). I have a web form (ERB) where none
of the fields can be blank and I need client side validation to show
fields are empty.

I want to get the value from text box field and pass to javascript to
find out if it is empty. As I realize, server side is getting mixed up
with client side and i am not getting the value passed  correctly.

Here is my code-- Can someone please guide (apologize the query is


          <td> <label for="txtHost"><h4>Host</h4></label></td>
          <td><input type="text" id="txtHost" name="txtHost"></td>
        <@str = txtHost.value>

<script language="javascript">
    function validateForm() {
          var x = '<%= @str %>'
        if (x == null || x == "") {
            alert("Host must be filled out");
            return false;
Afe4e7449ced41bb9e8456d4372d3887?d=identicon&s=25 Benjamin K. (benny1992)
on 2014-06-18 13:49
Maybe this could help you -

Greetings Benny
This topic is locked and can not be replied to.