开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜