Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Problems with insertbefore method

Problems with insertbefore method

abaddon
02-04-2005, 11:12 AM
this is my page:


<html>
<head>

<SCRIPT>
function createTextbox(){
// Create textbox object 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, cognome);
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Documento senza titolo</title>
</head>

<body>
<form 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>

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?
Thx

jbot
02-04-2005, 02:22 PM
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?


 

TOP

For more info

setting a minimum size
Auto Preview of Image 
Refresh with a query s
JS Validation obsolete
Javascript Pop up func
Slide show transitions
I'm a newbie...please!
how to write coding in
Advanced Debug Info 
.js file doesn't work 

News Archive

Adding Graphic To Text
re-direct form after s
pop up window controls
Clock on homepage - He
passing a param from a
Password Procection wi
document.title in same
focus onload 
Counting Wrong from Ri
Help needed on how to 

Related stories:

window.open By Using onClick in <option> tag?
contentEditable in Gecko
Combine Hightlight with Add and Delete Selected Row
Change background for different resoloutions?
Document.getElementById() has no properties
Add and delete rows dynamically to an HTML table .... ?
script does not work on Mozilla FIrefox when doctype is on the html code
smart menu

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics