Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
javascript convert dollars to egyptian pound

I have this form when the user put a number in dollar and i want to convert this number to egyptian pound

I want to use javascript to do that

let dollarInput = document.querySelector("[name='dollar']");
let result = document.querySelector(".result");


dollarInput.addEventListener("input", () =>{
  if(dollarInput.value !== "" && dollarInput > 0){
     let eG = dollarInput.value * 15.6;
     result.textContent =`{${dollarInput.value}} USD Dollar = {${eG.toFixed(2)}} Egyptian Pound`;
  } 
});
<form action="">
  <input type="number" name="dollar" placeholder="USD Dollar" />
  <div class="result">{0} USD Dollar = {0} Egyptian Pound</div>
</form>

I'm using addEventListener when i put a number to make a change in the div i want to print the value in dollar than en egyptian pound

but my code it's not working can anybody help me to know why and how should i do it

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should be checking whether the value of the input is greater than 0, not the input element itself.

let dollarInput = document.querySelector("[name='dollar']");
let result = document.querySelector(".result");


dollarInput.addEventListener("input", () =>{
  if(dollarInput.value !== "" && dollarInput.value > 0){
     let eG = dollarInput.value * 15.6;
     result.textContent =`{${dollarInput.value}} USD Dollar = {${eG.toFixed(2)}} Egyptian Pound`;
  } 
});
<form action="">
  <input type="number" name="dollar" placeholder="USD Dollar" />
  <div class="result">{0} USD Dollar = {0} Egyptian Pound</div>
</form>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!