admin管理员组

文章数量:1185142

i am a beginer to javascript.I want to show a hidden textbox on a button click.i do the bellow code, but it doesnt work.

What is the problem with my code?

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
        function display() {
            var z = prompt("enter your name...");
            if(z != null) {
                document.getElementById("demo").innerHTML = "thankyou " + z + "..";
                document.getElementById("case").style.visibility = 'visible';
            } else {
                document.getElementById("demo").innerHTML = "thankyou";
            }
        }
        </script>
        <title></title>
    </head>
    <body>
        <p id="demo">
            click on the button.....
        </p><button type="button" onclick="display()">submit</button>
        <form>
            <input type="text" id="case" name="myText" style="display:none">
        </form>
    </body>
</html>

i am a beginer to javascript.I want to show a hidden textbox on a button click.i do the bellow code, but it doesnt work.

What is the problem with my code?

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
        function display() {
            var z = prompt("enter your name...");
            if(z != null) {
                document.getElementById("demo").innerHTML = "thankyou " + z + "..";
                document.getElementById("case").style.visibility = 'visible';
            } else {
                document.getElementById("demo").innerHTML = "thankyou";
            }
        }
        </script>
        <title></title>
    </head>
    <body>
        <p id="demo">
            click on the button.....
        </p><button type="button" onclick="display()">submit</button>
        <form>
            <input type="text" id="case" name="myText" style="display:none">
        </form>
    </body>
</html>
Share Improve this question edited Jan 29, 2013 at 9:15 David 8,6407 gold badges51 silver badges71 bronze badges asked Jan 29, 2013 at 8:52 DjangoDevDjangoDev 9577 gold badges16 silver badges25 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 13

replace

document.getElementById("case").style.visibility='visible';

with

document.getElementById("case").style.display='block';

Change the style as display block instead of visibility,

document.getElementById("case").style.display='block';

or have your text box as visibility hidden instead of display:none

<input type="text" name=<name> style="visibility:hidden"/>

The following two statements will display the element with id "case":

document.getElementById("case").style.display='block'; 

or

document.getElementById("case").style.display='';

The following statement will hide the element with id "case":

document.getElementById("case").style.display='none'; 

Display:none works fine with HTML to hide a button

本文标签: javascriptHide and show a text fieldStack Overflow