Can anyone please help me through this….
I have two input fields in my form . One of which is hidden and I want to show it using a button. Now when i tried to show it using onClick() function its not responding…
can anyone give me code snippet to do so….
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function show()
{
document.getElementById('passwd').style.display="block" ;
}
</script>
</head>
<body>
<form action="demo.html" >
<input type="text" name="user" />
<br />
<input type="text" id="passwd" name="password" style="display:none;" />
<input type="button" onClick="show()" name="show" value="show" />
<br />
<input type="submit" value="OK" />
</form>
</body>
</html>
plz help
This is because of your
<input>declaration:When you call
show()JavaScript will attempt to resolve the symbolshowfirst; because you’re callingshow()from inlined code, the resolution takes place indocument, which attempts to resolve the symbol based on thenameoridattribute of your input box.Solutions
Rename the button:
Rename the function:
Don’t use in-line code:
See also
Don’t give event handler the same name as a field!
Javascript Function and Form Name conflict