tranquillo
Technical User
Hi...
I'm trying to make a form for adding elements into a xml file using javascript and DOM. I've tested the script on w3schools.com and most of the code works just the way I want it to. the problem is getting the value of a textfield from the form into the DOM part.
is there some DOM syntax that I have to use to fetch the values from the form?
here's the code:
the parts where the value is inserted direktly works fine. it's the one that gets the value from the form that's the problem.
(form name:form, textfield name:isbn, form uses "onsubmit" to call the funktion "skapa()"
######################################
<script type="text/javascript">
function skapa()
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"
xmlDoc.async="false"
xmlDoc.load("test.xml"
document.write("The original XML:"
document.write(xmlDoc.documentElement.text)
var newnode=xmlDoc.createElement("produkt"
document.write("*"
var isbn = document.form.isbn.value
document.write("*"
var child1=xmlDoc.createElement(isbn)
var child2=xmlDoc.createElement("forfattare"
var child3=xmlDoc.createElement("titel"
var child4=xmlDoc.createElement("antal"
var child5=xmlDoc.createElement("kostnad"
var child6=xmlDoc.createElement("rabatt"
var childcontent1=xmlDoc.createTextNode("123"
var childcontent2=xmlDoc.createTextNode("olof palme"
var childcontent3=xmlDoc.createTextNode("mitt liv som hund"
var childcontent4=xmlDoc.createTextNode("1"
var childcontent5=xmlDoc.createTextNode("60"
var childcontent6=xmlDoc.createTextNode("0"
document.write("*"
child1.appendChild(childcontent1)
xmlDoc.documentElement.appendChild(child1)
child2.appendChild(childcontent2)
xmlDoc.documentElement.appendChild(child2)
child3.appendChild(childcontent3)
xmlDoc.documentElement.appendChild(child3)
child4.appendChild(childcontent4)
xmlDoc.documentElement.appendChild(child4)
child5.appendChild(childcontent5)
xmlDoc.documentElement.appendChild(child5)
child6.appendChild(childcontent6)
xmlDoc.documentElement.appendChild(child6)
document.write("*"
newnode.appendChild(child1)
newnode.appendChild(child2)
newnode.appendChild(child3)
newnode.appendChild(child4)
newnode.appendChild(child5)
newnode.appendChild(child6)
xmlDoc.documentElement.appendChild(newnode)
document.write("*"
document.write("After appending the new node:"
document.write(xmlDoc.documentElement.text)
}
</script>
######################################
I'm trying to make a form for adding elements into a xml file using javascript and DOM. I've tested the script on w3schools.com and most of the code works just the way I want it to. the problem is getting the value of a textfield from the form into the DOM part.
is there some DOM syntax that I have to use to fetch the values from the form?
here's the code:
the parts where the value is inserted direktly works fine. it's the one that gets the value from the form that's the problem.
(form name:form, textfield name:isbn, form uses "onsubmit" to call the funktion "skapa()"
######################################
<script type="text/javascript">
function skapa()
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"
xmlDoc.async="false"
xmlDoc.load("test.xml"
document.write("The original XML:"
document.write(xmlDoc.documentElement.text)
var newnode=xmlDoc.createElement("produkt"
document.write("*"
var isbn = document.form.isbn.value
document.write("*"
var child1=xmlDoc.createElement(isbn)
var child2=xmlDoc.createElement("forfattare"
var child3=xmlDoc.createElement("titel"
var child4=xmlDoc.createElement("antal"
var child5=xmlDoc.createElement("kostnad"
var child6=xmlDoc.createElement("rabatt"
var childcontent1=xmlDoc.createTextNode("123"
var childcontent2=xmlDoc.createTextNode("olof palme"
var childcontent3=xmlDoc.createTextNode("mitt liv som hund"
var childcontent4=xmlDoc.createTextNode("1"
var childcontent5=xmlDoc.createTextNode("60"
var childcontent6=xmlDoc.createTextNode("0"
document.write("*"
child1.appendChild(childcontent1)
xmlDoc.documentElement.appendChild(child1)
child2.appendChild(childcontent2)
xmlDoc.documentElement.appendChild(child2)
child3.appendChild(childcontent3)
xmlDoc.documentElement.appendChild(child3)
child4.appendChild(childcontent4)
xmlDoc.documentElement.appendChild(child4)
child5.appendChild(childcontent5)
xmlDoc.documentElement.appendChild(child5)
child6.appendChild(childcontent6)
xmlDoc.documentElement.appendChild(child6)
document.write("*"
newnode.appendChild(child1)
newnode.appendChild(child2)
newnode.appendChild(child3)
newnode.appendChild(child4)
newnode.appendChild(child5)
newnode.appendChild(child6)
xmlDoc.documentElement.appendChild(newnode)
document.write("*"
document.write("After appending the new node:"
document.write(xmlDoc.documentElement.text)
}
</script>
######################################