Jason S.
Jason S.

Reputation: 13

jquery change form action

There are definitely questions out there to help on this, but I can't seem to get mine working...

Trying to base my form action off of a menu. Obviously have something wrong and would appreciate any thoughts!

$("#role").change(function() {
    if ($(this).val() == "audience");
    var action = "./";
    } else {
    var action = "http://google.com";
$("#landing_form").attr("action", action);
});

  <form action="./" method="post" id="landing_form">
    <select name="role" id="role">
      <option value="audience">Audience</option>
      <option value="presenter">Presenter</option>
      <option value="moderator">Moderator</option>
    </select>

Upvotes: 1

Views: 6129

Answers (1)

adeneo
adeneo

Reputation: 318182

There are some syntax errors, missing curlybraces etc.

$(function() {
    $("#role").on('change', function() {
        if (this.value == "audience") {
            var action = "./";
        } else {
            var action = "http://google.com";
        }
        $("#landing_form").attr("action", action);
    });
});

Upvotes: 4

Related Questions