D
Damo
Hi
I'm new to javascript and i'm trying to create a simple form that:
has a text field
and a button
when the page is initially loaded the text field is not visible.
Pressing the button is supposed to make the text field visible
This is the code I have
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<script src = "srcipt.js" type="text/javascript"></script>
<form>
<fieldset id="testField">
<legend>Test</legend>
Test Field  <input type="text"/>
</fieldset>
<fieldset>
<legend>Test</legend>
<button type ="button" id="buttonfield" >Show field</button>
</fieldset>
</form>
</body>
</html>
The Javasrcript(in an external file)
if(window.attachEvent)
{
window.attachEvent('onload', setupForm);
}
else if(window.addEventListener)
{
window.addEventListener('load', setupForm,true);
}
function setupForm(someEvent)
{
document.getElementById("testField").style.display="none";
var field = document.getElementById"buttonField");
if(window.attachEvent)
{
field.attachEvent('onclick', handleClick);
}
else if(window.addEventListener)
{
field.addEventListener('click', handleClick,true);
}
}
function handleClick(someEvent)
{
document.getElementById("testField").style.display="";
}
Its not working and i have no idea why, Can anyone please help? Thanks
I'm new to javascript and i'm trying to create a simple form that:
has a text field
and a button
when the page is initially loaded the text field is not visible.
Pressing the button is supposed to make the text field visible
This is the code I have
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<script src = "srcipt.js" type="text/javascript"></script>
<form>
<fieldset id="testField">
<legend>Test</legend>
Test Field  <input type="text"/>
</fieldset>
<fieldset>
<legend>Test</legend>
<button type ="button" id="buttonfield" >Show field</button>
</fieldset>
</form>
</body>
</html>
The Javasrcript(in an external file)
if(window.attachEvent)
{
window.attachEvent('onload', setupForm);
}
else if(window.addEventListener)
{
window.addEventListener('load', setupForm,true);
}
function setupForm(someEvent)
{
document.getElementById("testField").style.display="none";
var field = document.getElementById"buttonField");
if(window.attachEvent)
{
field.attachEvent('onclick', handleClick);
}
else if(window.addEventListener)
{
field.addEventListener('click', handleClick,true);
}
}
function handleClick(someEvent)
{
document.getElementById("testField").style.display="";
}
Its not working and i have no idea why, Can anyone please help? Thanks