Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,737 members, 7,802,219 topics. Date: Friday, 19 April 2024 at 11:14 AM

Please I Need Help With This Javascript Issue - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Please I Need Help With This Javascript Issue (705 Views)

#get Responsive Website Developed Fast In Short Time. #php, #javascript.... / <html> Or Javascript / Please Guys Help Me With This Javascript Problem (2) (3) (4)

(1) (Reply) (Go Down)

Please I Need Help With This Javascript Issue by exhibit7432(m): 7:53pm On Feb 24, 2020
I need to know how to achieve what’s in the picture. A situation where which when the user clicks on the plus or minus sign or updates the text area.

The amount is incremented 50 times the number in the text area.

Please it’s urgent

Re: Please I Need Help With This Javascript Issue by stanliwise(m): 11:10pm On Feb 24, 2020
create an event listener that fires when someone click the button.
Extract the amount,
convert to integer or float.
multiplly by 50.
Insert it into the text area.

It is that simple.
Re: Please I Need Help With This Javascript Issue by DualCore1: 3:03am On Feb 25, 2020
exhibit7432:
I need to know how to achieve what’s in the picture. A situation where which when the user clicks on the plus or minus sign or updates the text area.

The amount is incremented 50 times the number in the text area.

Please it’s urgent


<input type="text" id="numberField" onkeyup = "return calculateFn()" />
<p>Amount: <span id="result">--</span></p>
<button id="plusBtn" onclick="return plusBtnFn()">
+
</button>
<button id="minusBtn" onclick="return minusBtnFn()">
-
</button>


<script>
let numberField = document.querySelector('#numberField');
let result = document.querySelector('#result');

result.innerText = numberField.value * 50;

plusBtnFn = () => {
//parseint is used here cuz the plus sign in JS is for concatenation, without parseint it will treat the operand as a string and concatenate it with 1, thats not what we want.
numberField.value = parseInt(numberField.value) + 1;
result.innerText = numberField.value * 50;
}

minusBtnFn = () => {
numberField.value -= 1;
result.innerText = numberField.value * 50;
}

calculateFn = () => {
result.innerText = numberField.value * 50;
}
</script>


You can see my codepen for the working demo
https://codepen.io/sawyerrken/pen/dyoNjmP
Re: Please I Need Help With This Javascript Issue by DualCore1: 3:37am On Feb 25, 2020
Made some further edits to the codepen, you can run the demo there
Re: Please I Need Help With This Javascript Issue by exhibit7432(m): 8:26am On Feb 25, 2020
Thanks so much dualcore1.

You be baba

(1) (Reply)

Ecommerce Online Store + SEO + Free Domain + Free Hosting For Sale! ==> Enter / 50,000 USA Contacts For Mailchimp Or Campaigns / I Want To Buy An Old Facebook Account

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.