What is the most efficient way to fill an input field using jQuery with only two inputs?

I am working with a set of five input elements, all sharing a class called "cheque". Is there a way to selectively fill only one of these inputs using jQuery?

Unfortunately, I am unable to utilize the validator jQuery library for this task.

The following is an excerpt from my HTML file:

<input class="cheque" id="chmomtaz" placeholder="ریال" type="text" style="width: 100%" >
<input class="cheque" id="chkimia" placeholder="ریال" type="text" style="width: 100%" >
<input class="cheque" id="chrash" placeholder="ریال" type="text" style="width: 100%" >
<input class="cheque" id="chsandal" placeholder="ریال" type="text" style="width: 100%" >
<input class="cheque" id="chchob" placeholder="ریال" type="text" style="width: 100%" > 

Answer №1

Hello @hasan movahed, your technique seems effective but to better suit your requirements, you can achieve the same result with this approach:

$('.cheque').on("keyup", function() {
    $('.cheque').not(this).val('');
});

By using this code snippet, you will be able to clear all other input fields without rendering them inactive.

Answer №2

I stumbled upon this issue.

Give this a shot:

$('.check').on("keyup", function() {
  $('.check').not(this).prop('disabled', this.value.length === 0 ? false : true);
});

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 progress bar on a website to indicate loading status until the entire page has

Looking to display a progress bar or loading popup on my web page until it is fully loaded. The page is quite heavy due to the presence of an HTML editor using jQuery, which takes significant time to load. During this loading period, I want to have a prog ...

What is the best way to use absolute positioning in React Native to align an element with its grandparent?

I am trying to position a Font Awesome icon in a React Native project using absolute positioning relative to the grandparent element, rather than its direct parent. After some research, I came across the following information on this page: https://reactna ...

Using AJAX to get the response from a static [webmethod] - a guide

On my Default.aspx page, I have the following PageMethod: [WebMethod] public static string Hello() { return "Hello"; } I want to set the text of a div to whatever is returned via AJAX: <div id="ajaxDiv"></div> Below are two methods I us ...

tips on adjusting images to the size of the screen without them being on html files

I understand that sharing links may not be appropriate for this forum, but I'm unsure how else to seek assistance. My apologies for any inconvenience. I am currently working on a website for a doctor, and the image you see is of a patient. I'm ...

Creating an artistic blend by layering p5.js drawings over images in an HTML canvas

I'm having a tough time solving this issue. My goal is to overlay circles on top of an image, ideally using HTML for the image. However, I just can't seem to make it work. let img; function setup() { createCanvas(800,800); img = loadImage(&qu ...

Having trouble passing multiple parameters in a jQuery AJAX request?

I'm currently working on implementing a .NET web service (asmx) using JSONP with guidance from this helpful tutorial. When I try calling my webservice with only one parameter, everything runs smoothly. However, the moment I attempt to call it with mu ...

How to use absolute positioning in CSS within a scrollable container using Bootstrap 4

I'm attempting to create a scrollable div with absolute positioned children inside. My goal is to keep the absolute positioned elements visible even when the parent is scrolled. I am aware that I need to set the parent element to position: relative in ...

The information I input into this form is failing to be stored in the WAMP database

After implementing this PHP code, there are no error messages being displayed when I submit the HTML form. However, the data is not being added to the WAMP table. <?php error_reporting(E_ALL); ini_set('display_errors', 1); //$user_name = "roo ...

What is the best way to connect individual buttons to a dynamic div that displays different content depending on the button clicked?

Hey there! I'm diving into the world of JavaScript and HTML, and I need some guidance on creating a menu that can toggle visibility of specific content in div(s) depending on which button (picture1-12) is clicked. My idea is to have one div that can d ...

I am seeking assistance with refining my responsive side menu code

I've been diligently working on my project for about a week now, but I've encountered a small yet incredibly frustrating issue that has me stumped. The problem lies in the functionality of the responsive sidemenu with multiple dropdowns that I ha ...

jQuery does not support CSS pseudo-code

I'm having trouble with my CSS pseudo-code not being recognized by jQuery. Here is the code I'm using: CSS: h1 { background: red; width: 100px; display: inline-block; } h1:after { content:" | "; background:blue; display ...

Has anyone successfully integrated parsley.js with a lightweight custom version of jQuery?

In my project, parsley.js is the only dependency that relies on jQuery. I am looking to minimize the impact of including jQuery by eliminating any unused jQuery modules. I attempted to create a custom version following the guidelines on the jQuery GitHub ...

Adjustable div element and percentage-based height are not functioning correctly

I am facing a minor issue while attempting to create a responsive div with an image background. The div does not match the size of the image: 540px-290px When I resize the browser, the two divs do not resize together. In each div, there is a background ...

Response from the AJAX server

I need help with handling server-side code that returns either true or false upon checkout fulfillment. The console log displays {"success": true, "message": "Added to db"}. How can I modify the ajax success condition to perform different actions based on ...

What is the best way to utilize multiple props within a single callback function declared in a template literal when using React styled-components?

I recently incorporated styled components into my React project, but I'm encountering difficulty using multiple props to define styles in my components. Here's the crux of the problem: const sizes = { lg: css` width: 200px; h ...

What methods are available for implementing hover effects within attributes using a JavaScript object?

const customPanelStyle = { 'background-color': 'red', 'border': '1px solid green', ':hover'{ 'background': 'blue' } } class some extends React.Component{ rende ...

Encountering problems when attempting to effectively filter a list of products using data

<div id="prod"> <div class="content" data-brand="Andrew" data-price="1000" data-store="JCPenny">Andrew</div><br /> <div class="content" data-brand="Hill" d ...

How can I horizontally center an element in CSS/HTML if auto-margin does not produce the desired result?

This is a snippet of the CSS code I'm using for my menu: ul { text-align: left; display: inline; margin: auto; width: 50%; position: fixed; top: 0; list-style: none; } I've attempted to use auto-margin left and right ...

Implementing PHP logic for adding a class to an HTML tag

I have a PHP file that handles the sending of my form. Everything is functioning correctly, but I need to make a small modification. When the message is successfully sent, I want PHP to dynamically add the "active" class to a specific div in my HTML. This ...

Using the 'name' parameter in handling forms in PHP

I have a table in my database called 'iso' which has two columns - one for the name of the ISO certificate and another for the code. In the code snippet below, I am attempting to display the names of all certificates as clickable submit buttons. ...