Enhance your form submission with the power of jQuery and jQuery mobile

I am attempting to create a collapsible sidebar on my website that includes a search form with a search field and submit button.

In order to accomplish this, I have included the following scripts:

https://code.jquery.com/jquery-1.11.3.min.js

and

https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js

However, when using these scripts together, the form does not submit as expected. Instead, it appears to add the parameters to the URL and then triggers some form of preventDefault. This issue led me to believe that I may be using an outdated version of jQuery. To test this theory, I attempted to update to:

https://code.jquery.com/jquery-3.2.1.min.js

Upon updating to the newer version of jQuery, I encountered several problems including the collapse feature no longer functioning and the overall style of the site being disrupted. Additionally, I was unable to recreate the issue in a fiddle due to their reliance on jQuery.

Sample 1 (Collapse works but form does not):

<html>

<head>
  <title>Test form</title>
  <meta charset="utf-8">
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>

<body>
  <div data-role="page" id="about">
    <div data-role="header">
      <h1>Header</h1>
    </div>
    <div data-role="main" class="ui-content">
      <div data-role="collapsible">
        <h1>Search</h1>
        <form method="get">
          <input name="test" type="text">
          <button type="submit">Send</button>
        </form>
      </div>
    </div>
  </div>
</body>

</html>

Sample 2 (Form works but Collapse does not):

<html>

<head>
  <title>Test form</title>
  <meta charset="utf-8">
  <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>

<body>
  <div data-role="page" id="about">
    <div data-role="header">
      <h1>Header</h1>
    </div>
    <div data-role="main" class="ui-content">
      <div data-role="collapsible">
        <h1>Search</h1>
        <form method="get">
          <input name="test" type="text">
          <button type="submit">Send</button>
        </form>
      </div>
    </div>
  </div>
</body>

</html>

To address the issue in the first sample, I attempted to change the input type from submit to button and manually trigger the form submission using the following piece of code:

$('#submitbutton').click(function() {
    $('#myform').submit();
});

Unfortunately, this approach did not resolve the issue. Any insights or suggestions would be greatly appreciated!

Answer №1

mobile version 1.4.5 is specifically designed to work with certain older versions and has not been tested on older versions above 2.0.

To learn more about this, visit this link: .

This could be the reason why your collapsible form is not working with version 3.2.1.

On the other hand, for version 1.11.3, developer console suggests that you load your form on a web server instead of local loading (e.g., C:/Folder/.html won't work; use browser extensions like https or http)

I hope this information proves helpful to you, as I am not a professional programmer and cannot provide you with a code fix myself.

Answer №2

My perspective was totally off base. jQuery mobile brings a host of automatic features such as submitting a form in the background via XHR request without refreshing the page.

In my opinion, they should provide clearer instructions on this feature because I struggled to understand it initially. The solution is: for `

<form action="#" method="get" data-ajax="false">

<a href="" data-ajax="false">

I hope this explanation helps someone else.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An error will be thrown if you try to pass an array attribute of an object as a prop to a React component

I'm trying to grasp why passing an array attribute of a data object into a Component as a prop is causing issues. Is this due to my understanding of how React functions, or are there potential pitfalls in this scenario? Any insight would be greatly ap ...

Move your cursor over an image to reveal another image on top without impacting the image underneath by using background-image

Is there a way to create an effect where hovering over a specific book image will display a checkmark, indicating selection upon click? Ideally, users should be able to press alt (cmd on mac) to select multiple books simultaneously. Check out the HTML bel ...

How to access nested JSON elements in Javascript without relying on the eval function

Below is a JSON that I am trying to access. { "orders": { "errorData": { "errors": { "error": [ { "code": "ERROR_01", "description": "API service is down" } ] } }, "status": " ...

What could be causing my image to not completely fill the background?

I'm struggling to get my background image to fit 100% screen width and height. Unfortunately, the image isn't showing up at all. Can anyone tell me what I'm doing wrong? Below is the code I've tried, but for some reason, it's not ...

Issue with ng-grid in AngularJS: Data does not appear after resizing columns

Currently, I am encountering a problem where ng-grid data is not being displayed when column resizing occurs after changing the column names. To demonstrate this issue, I have created a plunkr at - http://plnkr.co/edit/eV9baoDOV9A46FZmKW8G?p=preview I wo ...

Utilizing AJAX to integrate the Google Maps Direction API

Currently, I am developing a small website that utilizes the Google Maps API and AJAX to load directions based on selected locations from a dropdown menu. The database stores latitude and longitude coordinates of various locations, which are retrieved via ...

The importance of precision in a written text

When it comes to being specific, I usually pride myself on my skills. However, there's one particular challenge that I can't seem to crack. Here's the scenario: Imagine you have a list structured like this: <ul class="dates"> < ...

Encountering a lack of response when making an ajax call to CouchDB

Being relatively new to CouchDB, I appreciate your patience. Currently, I have set up an instance of CouchDB on a VM. It can be accessed without any issues through the browser via futon or directly at: http://192.168.62.128:5984/articles/hot_dog Althoug ...

Issues are arising post-deployment despite JavaScript being enabled in the browser, including a <noscript

Upon deployment, an error appeared in the network tab stating: We're sorry but app-frontend doesn't work properly without JavaScript enabled. Please enable it to continue. Here is the code snippet from the index.html file of a vueJS app: <bo ...

Retrieving information from an AJAX callback

Is there a way to extract the URLs from PHP data? Here is an example script that may help you achieve this: PHP $query = 'SELECT * FROM picture LIMIT 3'; $result = mysql_query($query); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { ...

Leveraging electron-usb alongside electron

I attempted to integrate the electron-usb library into my electron project. Upon running npm start with require('electron-usb') in my index.html file, an error is displayed in the console: Uncaught Error: The specified procedure could not be fo ...

Is it possible to exchange CSS classes for a specific group of elements using JQuery?

I have two list items listed below: <li name="luxury" class="cars luxury> <div id="featured_lux" name="featured" class="carImg_lux col2_lux "> My Luxury Car<img border="0" class="car-im ...

Here's a unique version: "Create a table with a two-layered structure by placing the x-axis data at the top of the table and rotating all text horizontally to be vertical."

My goal is to design my table similar to the screenshot provided in the link below: https://i.sstatic.net/DfcW2.png Currently, my table looks like this: https://i.sstatic.net/DgoHS.png The first column of my table represents issuetype\assignee. Th ...

swapping out an input parameter

Looking for a more efficient way to replace a string in a textarea without causing issues with the script due to "&" characters? function doRequest(){ var str = $('textarea#tr').val(); $.ajax({ type: "POST", url: "index.php?sd=t", d ...

Currently, my nextjs project is up and running smoothly in vscode. When I execute `npm run dev` in the terminal, everything seems to be working fine. However

Whenever I run npm run dev in my terminal to start a nextJS project, it shows the following output: > [email protected] dev > next dev ready - started server on 0.0.0.0:3000, url: http://localhost:3000 but when I try to access it in the browser, ...

Issue with getStaticProps in Next.js component not functioning as expected

I have a component that I imported and used on a page, but I'm encountering the error - TypeError: Cannot read property 'labels' of undefined. The issue seems to be with how I pass the data and options to ChartCard because they are underline ...

Storing checkbox values in a MySQL database using PHP

I am working on a project that involves two checkbox filters. My goal is to keep track of the count of checked checkboxes for each filter and store this information in separate columns in a MySQL table. Could someone please assist me in obtaining the coun ...

The float right attribute doesn't stay contained within the box; instead, it drifts outside the box

I've been struggling to keep this box fixed at the top of the browser, but I'm facing an issue with the positioning on the right side. I can't seem to figure out how to solve it, so I'm reaching out for some help. #StickyBar #RightSide ...

Is there a way to eliminate the white border on a pie chart in Chart.js V2.6.0?

https://i.sstatic.net/YIFQx.png Currently, I am working with a pie chart using Chart.js (version 2.6.0), and I am looking to remove the white lines that appear between the slices. Can anyone provide me with a solution for achieving this? I have already a ...

Unable to establish a connection to localhost using Javascript due to net::ERR_CONNECTION_REFUSED error

My setup includes a node.js express server running my API on port 7070 and a Flask server hosting my webpage on port 5000. While I can successfully access my API from the server using curl with curl http://localhost:7070/latest, I encounter issues when try ...