Configure the input to accept integer values

This page that I have developed is designed for entering Latitude and Longitude values.

<div class="container ">
        <form class="entry">
            <div class="aligncenter">
                <h5 style="color:MediumTurquoise; font-weight:100; font-family:'Oswald', sans-serif; letter-spacing: 0.1em;">Please input the coordinates</h5>
                <div>
                    <input type="number" min="0.0000000" max="999.9999999" id="lat" placeholder="Latitude">
                    <input type="number" min="0.0000000" max="999.9999999" id="long" placeholder="Longitude">
                    <button class="btn-rounded btn-normal btn-medium btn-primary" id="search" value="get Info">Submit</button>
                </div>
            </div>
        </form>
    </div>

Upon providing the input, a script using Jquery gets triggered to fetch information from a REST API.

 <script>
    var data;
    $(document).ready(function () {
        $("#search").click(function () {

            let lat = $("#lat").val();
            let long =$("#long").val();
            if (lat == "" || long == "") {
                alert("Kindly provide both latitude and longitude values");
                return;
            }
            else {
                document.getElementById('message').style.visibility = 'hidden';
                document.getElementById('note').style.visibility = 'visible';
                $('#note').show();
                $('.show-onclick').show();
                $.ajax({

                    type: "GET",
                    url: `https://rest.soilgrids.org/query?lon=${long}&lat=${lat}&attributes=ORCDRC,PHIHOX,PHIKCL,BLDFIE,CLYPPT,SLTPPT,SNDPPT,WWP`,
                    dataType: "json",
                    success: function (response) {
                        console.log(response);
                        // Retrieving and displaying specific properties from the response

                    },
                    error: function (error) {
                        console.log(error);
                        alert("No data found");

                    }
                })

            }
        })
    })
</script>

Despite the successful display of information on initial search, I encounter difficulties in refreshing the page to show new data after subsequent inputs. The issue doesn't seem to be related to the input type as initially thought. While the console displays the information, it fails to reflect on the page.

Answer №1

You might want to consider including type="button" in your submit button declaration.

Answer №2

By default, a button element is categorized as type button unless it is placed within a form.

If the button is nested inside a form, it will be considered as type submit, functioning similarly to <input type="submit" />, which submits the form and reloads the page.

There are two ways to use the button:

  • Place your button outside of any form without specifying a type attribute
  • Include it within a form and specify type="button"

$("#btn").click((evt) => {
  console.log("lat="+$("#lat").val()+" long="+$("#long").val());
});
<input id="lat" type="text" />
<input id="long" type="text" />
<button id="btn">Submit</button>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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

The swap feature in drag-and-drop does not have a defined function

I am currently developing a to-do app that utilizes drag and drop functionality to reorder items in the list. However, I have encountered an issue where swapping elements works perfectly for the first five elements but throws errors when dealing with the s ...

Using jQuery to Interpret JSON Data from Google Finance

I am struggling to properly parse this JSON data and it's returning blank. I'm not sure if I'm doing it correctly. Could you take a look at it for me, please? $.getJSON('http://www.google.com/finance/info?infotype=infoquoteall&q=S ...

Activate Dropdown on hover and automatically close the menu when a link is clicked

Looking for assistance with a Dropdown menu that opens on mouse hover but needs to close when a link is clicked within the menu. Do you think JavaScript would be necessary for this function? .dropdow { position: relative; ...

Incorporating JSON data into an array using d3

I'm currently working on mapping JSON data to an array variable in d3. Below is the JSON I am using: [ { "Impressions": "273909", "Clicks": "648", "CPM": 4.6388278388278, "Cost": 1266.4, "CPC": 1.9543209876543, "Campaign": "C ...

Split a cell filled with various values into individual rows

I need to split each cell with multiple words into individual rows while keeping its rating and sysnet value intact when combined. I tried to use someone's pandas_explode library, but for some reason, VS Code doesn't recognize it. Is there a way ...

The icons at the bottom of the page are not properly aligned

I am having trouble aligning my footer icons, specifically the first 2 images. While the bootstrap icons are centered correctly, the first 2 images are not aligning as expected. I have tried various methods like align-items-center, justify-content-center, ...

Using Thymeleaf within Javascript code to generate a URL?

Here is my question: The project's base URL is : The test page URL is :, and on this page, I have included a JavaScript file called datatable.packer.js using the following code: <script type="text/javascript" th:src="@{/resources/js/datatable ...

Tips for transferring the id from a delete button to a delete button in a popup dialog box

In my frontend application, there is a table where each row corresponds to an item. For every row, there is a "Remove" button that triggers a warning popup upon being clicked. The intention is to pass the item's ID in this popup so that if the user co ...

What is the correct way to interpret the URL of attachments in messages?

I'm trying to create a feature where, when someone sends an image or a link of an image (like with Imgur), the attachment's URL gets logged in a specific channel. I attempted to achieve this using if(message.attachments.length > 0 || message. ...

Utilizing jQuery to toggle nested divs within identical parent divs when they contain more than three elements using the :nth-child selector

Within my HTML markup, I have created two parent div elements that are exactly the same but contain different content. My goal is to have a functionality where if a parent div has more than 3 child div elements, a "show more" text will be displayed at the ...

Generate an index for searching on a JSON column and allocate it to a designated tablespace

I'm attempting to generate a search index using a designated tablespace, as shown below: CREATE SEARCH INDEX EX_INVOICE_LINE_ITEM_ADDITIONAL_INFO ON EX_INVOICE_LINE_ITEM(ADDITIONAL_INFO) TABLESPACE MX_DATA FOR JSON The operation works without the tab ...

Confirmation message does not display in HTML contact form

After downloading an impressive website template, everything seems to be working smoothly except for the contact form. Unfortunately, there is no longer any support available for this template, so I find myself seeking help here. The contact form does sen ...

Merge two arrays of objects containing Google Map coordinates

I am facing a challenge with merging two object arrays that have similar values. var Cars = [{ lat: 42, lng: -72 }, { lat: 40.7127837, lng: -74.0059413 }, { lat: 40.735657, lng: -74.1723667 }]; var Trucks = [{ lat: 43, lng ...

Determine if the object's value is present

My current JavaScript setup looks like this: var NAMES = []; function INFO(id,first,middle,last){ var newMap = {}; newMap[id] = [first, middle, last]; return newMap ; } Next, I have the following code block: for (var j = 0; j < NUMBER.leng ...

AngularJS modal popup with a selectable table

Is there a way to open a modal popup containing a table in my application? I'm trying to achieve this by setting up an event in my app.js that triggers the modal when a row is clicked. Additionally, I need to update a field with the selected item&apos ...

Vue.js is displaying an error message stating that the data property is

I am struggling to access my data property within my Vue.js component. It seems like I might be overlooking something obvious. Below is a condensed version of my code. The file StoreFilter.vue serves as a wrapper for the library matfish2/vue-tables-2. &l ...

Creating styles for different screen sizes including mobile devices, low-resolution desktops, and high-resolution desktops

One of the techniques I'm using involves analyzing both the horizontal and vertical screen dimensions to differentiate between mobile devices and desktops, as well as distinguish high-resolution from low-resolution desktop displays. In order to achie ...

Activate tooltip when hovering over the <img> element

I am having trouble implementing a tooltip using CSS for an <img> element. While I have successfully added a tooltip to <a href> </a> tags, applying the same functionality to an <img> tag has proven difficult. http://jsfiddle.net/ ...

Node Js issue stemming from unaddressed promises leading to rejection

Hi, everyone! I'm currently facing some challenges while trying to deploy this API. The error message I keep getting is: "UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error may have occurred due to either throwing inside an asyn ...

There seems to be an issue with the AngularJS ng-click function not functioning properly

I'm attempting to insert a link tag with a filter into an HTML content. The HTML content is bound using ng-bind-html and the link tag includes an ng-click directive. However, I'm facing an issue where the ng-click function is not functioning. He ...