+ 3
Call function when button on click
Hi everyone, Now I writing some JS codes and I've some issues. I create a text box and button in html as follow: <input id="txtuname" type="text" name="uname" class="txtbox" /> <input name="btnLogin" type="button" class="btn" value="Login" onclick="chkblank" /> I would like to alert messages by clicking button when the text box is empty text. So, I wrote follow scripts but it not working. <script type="text/javascript"> function chkblank(){ var bc=document.getElementsByName("uname"); if (bc.value==""){ alert("Username is blank"); }; } </script> Could you please help with some ideas for me? Thanks. Ko Dway
2 Respostas
+ 4
://You have missed many things in html anddl css like taking value from tag name but from invalid etc
//solved
<input type="text" id="uname" class="txtbox" />
<input type="button" class="btn" value="Login" onclick="chkblank()" />
<script>
function chkblank(){
var bc=document.getElementById("uname").value;
if (bc==""){
alert("Username is blank");
};
}
</script>
+ 2
Great!!
I thought the value attribute need to add in if statement.
Thanks a lots and already solved. 😁
Ko Dway