Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want to use onclick for button ,, and if textbox is empty show alert on top of page (TExtbox is empty) , and stay on same page without reload or refresh

how to do this using jquery /javascript onclick function





regards
maulik shah
Posted

 
Share this answer
 
Hi Mauli,

You could try this code
XML
<!DOCTYPE html>
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
function validate() {
    var text = document.getElementById('txtbx').value;
    if (text == "")
    {
      alert('TextBox is empty');
      location.reload();
    }
}

//-->
</script>
<input type="text" id="txtbx"/>
<input type="button" onclick="validate();" value="Click me"/>
</body>
</html>

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900