+ 3

Clear Input Button

How do I clear the input of my form After calling on a function to perform a calculation based on the users input

7th May 2018, 10:58 PM
love
23 Answers
+ 7
i'll make a quick code...
7th May 2018, 11:05 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
reference the DOM of your input and set the value = "" or " " when the calculation is complete [end of the function before closing it]
7th May 2018, 11:01 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
are you using the <form> tag?
7th May 2018, 11:07 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
user cyk got it ready and done ;)
7th May 2018, 11:10 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
cyk's code clears the previous input on focus (when you click the input box). its a lot nicer IMO but we'll help regardless
7th May 2018, 11:13 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
cyk Yeah lol it will require JS code; unless theres a CSS alternative but im no CSS guru
7th May 2018, 11:15 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
cyk you want to help him or her make something simple?
7th May 2018, 11:15 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 6
cyk yep that sounds like the solution ;)
7th May 2018, 11:19 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 5
Here love. You've got your answer. Played around with one of the codes I posted earlier https://code.sololearn.com/Ws19kJz1Bc72/?ref=app
7th May 2018, 11:41 PM
cyk
cyk - avatar
+ 4
I didn't code it to do that. I only solved your "clear input field on button click issue"... The rest doesn't have much to do with JS per say, it is a function that gets the value of the input field and does a conversion and returns it. Give it a try and we will help if you get stuck. ☺
7th May 2018, 11:46 PM
cyk
cyk - avatar
+ 3
Aaaaaah... You want the user to click on a button that will clear the field. Is that it?
7th May 2018, 11:11 PM
cyk
cyk - avatar
+ 3
「HAPPY TO HELP」 Seems we were answering the wrong question? This needs JS code
7th May 2018, 11:13 PM
cyk
cyk - avatar
+ 3
「HAPPY TO HELP」 love Nah. JS. Event handler for the clear button. We could also do in the button stuff in HTML, onclick="this.form.reset();". But the button will have to be with the input fields between form tags
7th May 2018, 11:18 PM
cyk
cyk - avatar
7th May 2018, 11:19 PM
cyk
cyk - avatar
+ 2
Here. Look at line 15 of the first code, the part that has to do with onfocus and line 16 of the second code, the part that has to do with onfocus. They both do what you want, kind of. Basically when the user clicks in the input field it is cleared and ready to receive new inputs https://code.sololearn.com/Wte6t2yXQMvF/?ref=app https://code.sololearn.com/WAMXplm993Bk/?ref=app
7th May 2018, 11:08 PM
cyk
cyk - avatar
+ 2
Aight...thanks... Appreciate the help
8th May 2018, 12:06 AM
love
+ 1
How would that look like
7th May 2018, 11:04 PM
love
+ 1
Yes but when I do the solution disappears. The function is to convert Fahrenheit to Celsius and the clear the input
7th May 2018, 11:09 PM
love
+ 1
Then
7th May 2018, 11:09 PM
love
+ 1
I need a button to clear the input though
7th May 2018, 11:11 PM
love