DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Write List As XML To HTML Form - Javascript

  • submit to reddit
        Suppose that you have a draggable list as described at To send that list from a form, do

function listToXml(){
	var vList = document.getElementById('phonetic');
        var vLen  = vList.childNodes.length;
	var vXml  = "<ul>";
        for(var i = 0; i < vLen - 1; i++){
	    vXml = vXml + '<li>' + vList.childNodes[i].innerHTML + '</li>';
	vXml = vXml + '</ul>';
	document.myform.listfield.value = vXml;


	<ul id="phonetic" class="sortable boxy" style="margin-left: 1em;">

<form name="myform">
<input type="text" name="listfield" value="" size="60">
<input type="button" value="submit2" name="submit2" onClick="listToXml()">