Activity › Forums › Salesforce® Discussions › How to turn my input field empty on the button click?
Tagged: Custom Button, Input Field, Salesforce Code
-
How to turn my input field empty on the button click?
Posted by shariq on August 10, 2017 at 6:52 AMI am in situation where I need to get my input field empty on the button click, Please give the code if possible.
Parul replied 7 years, 8 months ago 3 Members · 2 Replies -
2 Replies
-
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 8 years, 9 months ago by
Radhakrishna.
-
This reply was modified 8 years, 9 months ago by
- [adinserter block='9']
-
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.