7

I want to change an invisible HTML input in to visible when I click a button as shown below.

My HTML line that create the hidden input is:

<input type="hidden" id="txtHiddenUname" value="invalid input" />

my JavaScript for changing the visibility is:

var y = document.getElementById("txtHiddenUname");
y.style.display= "inline";

But this couldn't make the hidden element to be visible.

Any ideas?

1
  • You have to change the value to "valid input", otherwise it's still invalid ? Commented Jul 14, 2013 at 11:06

2 Answers 2

6

You should change the type of input element as :

 y.setAttribute('type','text'); 
 //or
 y.type = 'text';

1) Either user java script inside body tag as below :

<input type="hidden" id="txtHiddenUname" value="invalid input" />

<script type="text/javascript">
var y = document.getElementById("txtHiddenUname");
y.type= "text";
</script>

OR

2) Use some event handler such as onload

<head>
<script type="text/javascript">
function on_load(){
    var y = document.getElementById("txtHiddenUname");
    y.type= "text";
}
    </script>
</head>

<body onload = "on_load()">

<input type="hidden" id="txtHiddenUname" value="invalid input" />

...

so that the DOM is ready.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried it and indeed it makes the text visible. but the visibility stays for milliseconds and it goes back to invisible mode.
use this code after some events occures on some element , like button click or someting else.
2

Here is not matter of CSS it's matter of attributes, So you need to change the attribute type from hidden to something else like text

Kindly check this [how-to-change-html-object-element-data-attribute-value-in-javascript][1]

check this: How to change HTML Object element data attribute value in javascript. To change the attribute value using jQuery or Javascript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.