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

04.08.2005
| 14881 views |
  • submit to reddit
        Suppose that you have a draggable list as described at http://tool-man.org/examples/sorting.html. 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++){
	  if(vList.childNodes[i].innerHTML){
	    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;">
		<li>alpha</li>
		<li>bravo</li>
		<li>charlie</li>
		<li>delta</li>
		<li>echo</li>
		<li>foxtrot</li>
        </ul>

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