Activity Forums Salesforce® Discussions How to turn my input field empty on the button click?

  • Radhakrishna

    Member
    August 11, 2017 at 8:57 am

    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!"
    return
    }
    else{
    do button functionality
    }
    }
    </script>

    • This reply was modified 7 years, 4 months ago by  Radhakrishna.
  • Parul

    Member
    September 16, 2018 at 1:13 pm

    Hi

    <!DOCTYPE html>
    <html>
    <head>
    <title>Jquery</title>
    <meta charset="utf-8">
    <script src='http://code.jquery.com/jquery-1.7.1.min.js'></script>
    </head>

    <body>

    <input type="text" id="message" value="" />
    <input type="button" id="sendButton" value="Send">

    <script>
    $(document).ready(function(){

    var checkField;

    //checking the length of the value of message and assigning to a variable(checkField) on load
    checkField = $("input#message").val().length;

    var enableDisableButton = function(){
    if(checkField > 0){
    $('#sendButton').removeAttr("disabled");
    }
    else {
    $('#sendButton').attr("disabled","disabled");
    }
    }

    //calling enableDisableButton() function on load
    enableDisableButton();

    $('input#message').keyup(function(){
    //checking the length of the value of message and assigning to the variable(checkField) on keyup
    checkField = $("input#message").val().length;
    //calling enableDisableButton() function on keyup
    enableDisableButton();
    });
    });
    </script>
    </body>
    </html>

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos