Button and Alert?
I have a button and a text.
If a user enters "Hi" in t开发者_StackOverflow中文版he textbox and then click on the button he should get a javascript alert "HELLO!" how can i make that ?
Thanks
Just add the following code in script:-
function hello()
{
if(document.getElementById("txtboxid").value == "HI")
alert("HELLO");
}
Call above function on the click event of the button.
<head>
<script type="text/javascript">
function sayHello()
{
theTextbox = document.getElementById("myTextbox");
alert("Hello!");
alert(theTextbox.value);
if(theTextbox.value == "Hi")
{
alert("You did enter Hi in the textbox!");
}
}
</script>
</head>
<body>
<input type="text" id="myTextbox" />
<button onclick="sayHello()" text="Click me!" />
</body>
精彩评论