If I omitt the second parameter (the insert point) in the insertbefore, it's all ok but if I specify it i get this error "cognome is not defined".
Where is the problem?
the second param has to be an element, not just a string, that's why.
btw: use code tags when posting code. read "posting guidelines" sticky to find out more!
abaddon
02-07-2005, 09:33 AM
In the example, the second parameter is the name of the element (cognome is the value of the attribute "name" of the input tag"). Should I use the getelementbyId function?
Willy Duitt
02-07-2005, 10:32 AM
You can not be taking shortcuts when using the DOM...
I suggest that you go back and read up on explicitly referencing objects... cognome might be an element name but that is not the way to properly reference it... May want to look at how your are referencing your form element also, I'm surprised the way this is written that it works at all.... At best it may work in IE but even that surprises me...
.....Willy
abaddon
02-07-2005, 11:30 AM
Ok, this the new code of my page:
<html>
<head>
<SCRIPT>
function createTextbox(){
// Create textbox object with value="First Choice" and then insert
// this element into the document hierarchy.
var newTextbox = document.createElement("<input name='name' type='text' id='fax' size='20' maxlength='20'>")
form1.insertBefore(newTextbox, document.form1.cognome);
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Documento senza titolo</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p>Nome
<input type="text" name="textfield">
<br>
<br>
Cognome
<input type="text" name="cognome">
<br>
<br>
Indirizzo
<input id="indirizzo" type="text" name="indirizzo">
</p>
<p>Stato civile
<select name="statocivile" onChange="createTextbox()">
<option value="Single" selected>Celibe/nubile</option>
<option value="Coniugato/a">Coniugato/a</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Invia">
</p>
</form>
</body>
</html>
But I get a new error at row 11 char 2.
"Argument is not valid". What's wrong?