Switch input trigger for immediate page refresh rather than standard input clearing

I want to customize how the clear input option functions. Normally, when you click on the X clear button, it clears the search input field.

Instead of clearing the search input, I would like the clear button to trigger a page reload.

This is the X button that I am referring to:

https://i.sstatic.net/U4Qfm.png

I have managed to create a clickable button inside the input box that accomplishes this, but I prefer to use the X button that appears in bootstrap once the user starts typing.

Javascript:

$('#clear').click(function () {

    $('#input-outer input').val('');
     window.location.reload();
});

HTML:

<div id="input-outer">
    <input type="text">
    <div id="clear">X</div>
</div>

CSS:

body {
    font-family:"Tahoma";
}
#input-outer {
    height:2em;
    width:15em;
    border:1px #e7e7e7 solid;
    border-radius:20px;
}
#input-outer input {
    height:2em;
    width:80%;
    border:0px;
    outline:none;
    margin:0 0 0 10px;
    border-radius:20px;
    color:#666;
}
#clear {
    position:relative;
    float:right;
    height:20px;
    width:20px;
    top:5px;
    right:5px;
    border-radius:20px;
    background:#f1f1f1;
    color:white;
    font-weight:bold;
    text-align:center;
    cursor:pointer;
}
#clear:hover {
    background:#ccc;
}

Instead of using this:

<div id="clear">X</div>

I'm attempting to target, but struggling:

input[type=search]::-webkit-search-cancel-button {
    -webkit-appearance: searchfield-cancel-button;
}

Here's a JSFiddle link that may help clarify my request: https://jsfiddle.net/mcmacca002/57mx3beq/1/

Thank you

Answer №1

In the code snippet provided, jQuery was not initially included, but after adding it, the functionality improved. However, be aware that this change may cause the page to reload.

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

What is the best way to display a popup using slimbox when the page loads, but only for the initial visit?

I have been exploring the idea of creating a function called popup("url") that checks for an existing cookie when the page body loads (onLoad - not ideal, I know). To implement this functionality, I used the code from this source and included it in my appl ...

Troubleshooting: Jquery UI Draggable - Cursor losing track of draggable element

I want to create a draggable popup with Jquery UI functionality, but I'm facing an issue where the cursor does not stay aligned with the popup element when dragged. When dragging the popup element to the left, the mouse cursor goes beyond the div elem ...

Scrolling behavior in two columns with sticky positioning

Both columns have varying heights, with the left sometimes higher than the right. I want them to start scrolling down simultaneously, but when the shorter column's content ends, it should stick to the bottom of the viewport and "wait" until the taller ...

Can the position of the popover be customized using the right and top properties?

Utilizing Bootstrap popover within a gantt chart, I am dynamically adjusting the position of the popover based on mouse hover. popover.css('left', event.pageX + 'px'); popover.css('top', event.pageY+ 'px') However, ...

Error: The property 'slice' cannot be read from an undefined value

I am currently working on a prototype recipe app called Forkify, which is being developed using Javascript, NPM, Babel, and Webpack. In this project, I am utilizing a custom API. API URL : forkify-api.herokuapp.com TO SEARCH RESULT This API returns a l ...

What is the best way to retrieve the latest files from a Heroku application?

Having recently migrated my Discord Bot to Heroku, I faced a challenge with retrieving an updated file essential for code updates. I attempted using both the Git clone command and the Heroku slugs:download command with no success in obtaining the necessar ...

What could be the reason behind jQuery replacing the entire span with .text?

I am dealing with the following HTML code snippet: <p><input id="revenue" type="text" value="100000" /><span id="howmuch"><a href="" class="ka_button small_button small_cherry" target="_self" style="opacity: 1; "><span>How Mu ...

Percy snap shot test cannot be executed in Testcafe due to the error message: npm ERR! The script 'test:percy' is

For my initial test with percy snapshot, I used the command below: npm run test:percy Unfortunately, an error message appeared when running the command: xxx.xxx@LPG002572 TC-Visual % npm run test:percy npm ERR! missing script: test:percy npm ERR! A com ...

"The program developed in Php/Ajax/jQuery/Javascript functions flawlessly on one server but encounters challenges on a different host. The mystery unrav

element, I'm encountering an issue that doesn't seem to be related to any specific code problem. There are no error messages indicating what steps I should take next. Here's the problem: I have a script similar to Facebook's wall feat ...

CSS shapes are extending beyond the boundaries of their parent container

I'm working on a small webpage and I am trying to incorporate 2 shapes in the background (see design screenshot attached). Using CSS, I created these shapes but I am facing an issue where the bottom right shape keeps extending beyond the container, ca ...

I am experiencing difficulty getting Bootstrap Columns to appear next to each other despite trying numerous solutions

Check out this code snippet: <div class="mainptext"> <h3><strong>Master the following:</strong></h3> <div class="container"> <div class="row"> <div class ...

What is the best way to instantly update $scope when working with non-angular code?

Working with a non-angular library requires establishing communication between them. <div id="MoipWidget" data-token="{{personaltoken}}" callback-method-success="successCB" callback-method-error="errorCB"></div> Upon page load, a token must b ...

Gathering all posts related to jagi astronomy

Within my MongoDB database, I have a collection called "post." My goal is to extract all post IDs that are not disabled from this collection. To achieve this, I utilized Jagi Astronomy, a Meteor JS package, to create the schema. However, when I implemented ...

Receiving a void value from the concealed field on the server end

When calling a JavaScript function and passing the value of a hidden field, I intend to use that value on the server-side. However, the hidden field's value is null. Client-Side Function function getDetails() { document.forms[0].HdnNode. ...

Can you modify a attribute value in one HTML file from another?

I currently have a website and I am looking to modify the aria-expanded value of an expandable paragraph on another page when I click on an anchor element in the main page. What changes do I need to make in my main.html file in order to update the aria-exp ...

Creating scalable React applications

Can you provide insights on the scalability of React Apps? What recommended approaches are typically employed to effectively handle and generate scalable states in web applications using Reactjs? * ...

Traverse the initial three elements of an array using JavaScript (React)

Let's say we have a collection of 5 items: const items = [ {id: 1, name: 'book', price: 50}, {id: 2, name: 'phone', price: 450}, {id: 3, name: 'fish', price: 80}, {id: 4, name: 'apple', price: 5}, {id: 5, name: ...

Obtain a randomly selected object from a React.js list based on its specific property

Having trouble retrieving a random item from my list. I've stored the list in an array and am using a function to get the desired item, but it's returning as undefined. Can't figure out where I'm going wrong! Looking to see the result ...

Retrieve the identifier attribute from a selection element and store it in a php variable

My PHP code generates an HTML dropdown menu. echo '<select id="myselect" name="myselect">'; while($row = mysql_fetch_array($query)) { echo '<option value="'.$row['categories'].'" id="'.$row[&a ...

The Express server powered by Node.js is failing to send responses back to HTTP requests initiated from a JavaScript file, despite successfully receiving and processing the requests

I am facing an issue with my setup where I have both a node-js server and an apache server running on the same machine. One of my javascript files is sending an HTTP request to the node-js server, which receives the file, reads the data, and puts it in the ...