Never been to DZone Snippets before?

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

About this user

Thomas Beutel http://www.beutelevision.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Write list as XML to HTML form - Javascript

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

   1  
   2  function listToXml(){
   3  	var vList = document.getElementById('phonetic');
   4          var vLen  = vList.childNodes.length;
   5  	var vXml  = "<ul>";
   6          for(var i = 0; i < vLen - 1; i++){
   7  	  if(vList.childNodes[i].innerHTML){
   8  	    vXml = vXml + '<li>' + vList.childNodes[i].innerHTML + '</li>';
   9  	  }
  10          }
  11  	vXml = vXml + '</ul>';
  12  	document.myform.listfield.value = vXml;
  13  }
  14  
  15  ...
  16  
  17  	<ul id="phonetic" class="sortable boxy" style="margin-left: 1em;">
  18  		<li>alpha</li>
  19  		<li>bravo</li>
  20  		<li>charlie</li>
  21  		<li>delta</li>
  22  		<li>echo</li>
  23  		<li>foxtrot</li>
  24          </ul>
  25  
  26  <form name="myform">
  27  <input type="text" name="listfield" value="" size="60">
  28  <input type="button" value="submit2" name="submit2" onClick="listToXml()">
  29  </form>
  30  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS