Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6378673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:02:20+00:00 2026-05-25T02:02:20+00:00

When I submit a form with Javascript I get the html response, it is

  • 0

When I submit a form with Javascript I get the html response, it is like it ignores the remote true parameter. If I submit the form with the submit button it does the AJAX and updates the page elements requested. So the only difference in the code is the presence of the onchange parameter and the button. Here is my code for the form:

<% form_tag('switch_car', :method => :put, :name => "switch_car", :remote => true) do %>
<div class="field">
    <label>Car Name:</label>
    <%= select_tag(:id, options_from_collection_for_select(active_cars, "id", "name"), :onchange => "submitForm('switch_car')", :include_blank => true)%>
</div>

<% end %>

Here is my Javascript function: just a simple submit.

<script type="text/javascript" charset="UTF-8">
function submitForm(formname){
    document.switch_car.submit();
}
</script>

Here is the HTML generated:

<form accept-charset="UTF-8" action="switch_car" data-remote="true" method="post" name="switch_car"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="PEbdqAoiik37lcoP4+v+dakpYxdpMkSm7Ub8eZpdF9I=" /></div><div class="field"> 
    <label>Car Name:</label> 
    <select id="id" name="id" onchange="submitForm('switch_car')"><option value=""></option><option value="9">Truck</option> 
<option value="10">Car</option></select> 
</div> 

Anybody know why the Javascript submit causes a different result than the button on the same form? If so can I get the Javascript submit to work with an Ajax result?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:02:21+00:00Added an answer on May 25, 2026 at 2:02 am

    Found the issue. I thought submitting the form with javascript would submit the form with the same remote => true option but it appears to bypass that. I had to submit using new AjaxRequest to get it working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ajax form that I would like to submit, and the response
JavaScript post request like a form submit shows you how to submit a form
I am using html, javascript & mod_python. I want to submit html form. To
I've got the following code: <script type=text/javascript> $(function(){ $(#AddMaps).submit(function(){ var $form = $('#AddMaps'); $.ajax({
I am unable to determine which form submit button is clicked during an Ajax
I'm trying to submit a form with javascript. Firefox works fine but IE complains
Javascript needed to prevent form submit if any of field is empty. all my
I'm using a javascript function to submit my form. This works in every browser
and actually i convert the url with javascript <script type=text/javascript> $(document).ready(function() { $('.search-form').submit(function() {
I have a website where we use Javascript to submit the login form. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.