0

So I have a quick question, I am trying to build an exchange react app that converts currency. I want to make by submit button disabled until the user type number in the desired input, I see a lot of answers but all of them using Jquery, have any solutions for only JS? my HTML code :

 <div id='mainHomeDiv'> <h1>Exchange</h1> <lable>From :</lable> <select> <option value=''>type</option> <option value='Dollar'>Dollar</option> <option value='Euro'>Euro</option> <option value='NIS'>NIS</option> </select> <input type='number' id='amountInput' placeholder='Amount'></input> <br /> <br /> <label>To :</label> <select> <option value=''>type</option> <option value='Dollar'>Dollar</option> <option value='Euro'>Euro</option> <option value='NIS'>NIS</option> </select> <br /> <br /> <button disabled="disabled">START</button> <br /> <br /> <button>Update</button> <button>Share on facebook</button> <button>View your exchange list</button> </div>

3
  • jQuery is "just JavaScript", you've also tagged this ReactJS. If you're using React then the answer becomes dramatically different. Commented Dec 30, 2020 at 15:47
  • You should learn how to use the label element properly. Without a for attribute or a form control inside it, a label is useless. You also need to spell label correctly. Commented Dec 30, 2020 at 15:48
  • 1
    stackoverflow.com/questions/30187781/… Commented Dec 30, 2020 at 15:54

1 Answer 1

0

hope this helps u

i have added an event onkeyup to your textbox code to run the function,

var enbbtn = document.getElementById("tgbtn"); var txtchng = document.getElementById("amountInput"); function enabledbtn() { if (txtchng.value.length > 0) { enbbtn.disabled = false; } else { enbbtn.disabled = true; } }
<div id='mainHomeDiv'> <h1>Exchange</h1> <lable>From :</lable> <select> <option value=''>type</option> <option value='Dollar'>Dollar</option> <option value='Euro'>Euro</option> <option value='NIS'>NIS</option> </select> <input type='number' id='amountInput' placeholder='Amount' onkeyup="enabledbtn()"></input> <br /> <br /> <label>To :</label> <select> <option value=''>type</option> <option value='Dollar'>Dollar</option> <option value='Euro'>Euro</option> <option value='NIS'>NIS</option> </select> <br /> <br /> <button id="tgbtn" disabled="true">START</button> <br /> <br /> <button>Update</button> <button>Share on facebook</button> <button>View your exchange list</button> </div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.