• #21553
    Salesforce | shariq shariq #560

    How to turn my input field empty on the button click?

    I am in situation where I need to get my input field empty on the button click, Please give the code if possible.

    Tagged: , ,


    Hello Shariq,

    Add a check when the button is clicked to see if there is any text. If there isn’t, pop up an alert box (or some other form of feedback) to tell the user to enter data, and don’t do the button functionality.

    <input id=”myText” type=”text” onkeyup=”stoppedTyping()”>
    <input type=”button” value=”Click to begin!” id=”start_button” onclick=”verify()” disabled/>

    <script type=”text/javascript”>
    function stoppedTyping(){
    if(this.value.length > 0) {
    document.getElementById(‘start_button’).disabled = false;
    } else {
    document.getElementById(‘start_button’).disabled = true;
    function verify(){
    if myText is empty{
    alert “Put some text in there!”
    do button functionality

    • This reply was modified 11 months, 1 week ago by Salesforce | Radhakrishna Radhakrishna.
Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?