Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide and show a text field

Tags:

javascript

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>
like image 354
DjangoDev Avatar asked Nov 29 '22 16:11

DjangoDev


2 Answers

replace

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

with

document.getElementById("case").style.display='block';
like image 159
user2001057 Avatar answered Dec 15 '22 05:12

user2001057


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"/>
like image 22
Selvakumar Ponnusamy Avatar answered Dec 15 '22 07:12

Selvakumar Ponnusamy