0

I'm trying out jQuery with Rails and I faced this problem. I want to have a jQuery submit handler for a button_to tag like this

<%= button_to "+", action: "execute", operation: "add", operand: "1" %>

which is actually converted to a form in the DOM like so

<form class="button_to" method="post" action="/execute?operand=1&amp;operation=add">
<input type="submit" value="+">
<input type="hidden" name="authenticity_token" value="mre8xqU4RBk2u+vCLrMQHYUHTNWtk0Ebn45OnvlXxUZcofqxArt9ZXJN63QlNq8Kei08FFo6Y4+OQgwH+vsVNw==">
</form>

I added a submit handler for this form which looks like this

$(document).ready(function(){
  ("form").submit(function(){
      alert("here");
    });
});

The alert doesn't get displayed when I submit the form. I also tried the solution of this question but it didn't help.

My aim is to set the value of the value of the operand attribute in the button_to tag to $(".operand").text() inside the submit handler. Operand is another text field in which the user has entered a numeric value.

1 Answer 1

2

Looks like you're missing a '$'

  ("form").submit(function(){
      alert("here");
   });

Should be

  $("form").submit(function(){
      alert("here");
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.