Jump to content

set a value for a object


buitrongkhiem

Recommended Posts

i have xml file . i use javascript,i got value of the node,but i want to set it in my object(text field,tag...)the first node, i set it in my text field , but the second node,i can't set it in my text field,i loop the value of the node to get value of node.please help me.

Link to comment
Share on other sites

Show us some code and some of the XML.
code : loadxmlDoc:
// JavaScript Documentfunction loadXMLDoc(quanlythuebao){	//tạo request lên severif (window.XMLHttpRequest)  {  xhttp=new XMLHttpRequest();  }  xhttp.open("GET","quanlythuebao.xml",false);xhttp.send();return xhttp.responseXML;}

code process:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>form customer managerment</title><style>body{background-image:url(metal_background.jpg);background-position:center;background-attachment:fixed;}table{background-image:url(ima.jpg);width:1000px;}#qlkh{MARGIN:auto;background-repeat:repeat;text-align:center;width:1200px;height:200px;}</style><script language="javascript" src="jquery-1.5.2.min.js"></script><script language="javascript" src="loadXMLDoc.js"></script><script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script></head><body><script language="javascript">$(document).ready(function (){//tên thuê baoxmlDoc = loadXMLDoc("quanlythuebao.xml");$('tr#dongmoi').hide();x = xmlDoc.getElementsByTagName("tenthuebao");for (i=0;i<x.length;i++)  {   a = x[0].childNodes[0].nodeValue;document.getElementById("name").value = a;aa = x[1].childNodes[0].nodeValue;document.getElementById("name").value = aa;aaa = x[2].childNodes[0].nodeValue;document.getElementById("name").value = aaa;  }//số thuê baox = xmlDoc.getElementsByTagName("sothuebao");for (i=0;i<x.length;i++)  {   b = x[0].childNodes[0].nodeValue; document.getElementById("phonenumber").value = b;  }//giới tính    x = xmlDoc.getElementsByTagName("gioitinh");for (i=0;i<x.length;i++)  {   c = x[0].childNodes[0].nodeValue; document.getElementById("######").value = c;  }       x = xmlDoc.getElementsByTagName("ngaysinh");for (i=0;i<x.length;i++)  {   d = x[0].childNodes[0].nodeValue; document.getElementById("date").value = d;  }  	x = xmlDoc.getElementsByTagName("diachi");for (i=0;i<x.length;i++)  {   e = x[0].childNodes[0].nodeValue; document.getElementById("address").value = e;  }  	x = xmlDoc.getElementsByTagName("tuoi");for (i=0;i<x.length;i++)  {   f = x[0].childNodes[0].nodeValue; document.getElementById("age").value = f;  }  	 x = xmlDoc.getElementsByTagName("nghenghiep");for (i=0;i<x.length;i++)  {   g = x[0].childNodes[0].nodeValue; document.getElementById("job").value = g;  }  	 x = xmlDoc.getElementsByTagName("hinhthuctb");for (i=0;i<x.length;i++)  {   h = x[0].childNodes[0].nodeValue; document.getElementById("type").value = h;  }      $('input[name=checkall]').click(function (){var status = this.checked;//sử dụng mô hình dom dùng this.attribute//mỗi thẻ input name = chon sẽ thực hiện 1 function thông qua hàm each()$('input[name=check]').each( 	function (){		this.checked= status; //set checked cho tất cả các thẻ input còn lại	});});$('#them').click(function (){$('#dongmoi').toggle(1000);});$('input[name=name]').append('asdasd')});</script><form action="" method="get"><div id="qlkh" ><script type="text/javascript">AC_FL_RunContent( 'codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','1200','height','200','src','banner','quality','high','wmode','transparent','pluginspage','http://www.macromedia.com/go/getflashplayer','allowscriptaccess','always','movie','banner' ); //end AC code</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1200" height="200">  <param name="movie" value="banner.swf" />  <param name="quality" value="high" />  <param name="allowScriptAccess" value="always" />  <param name="wmode" value="transparent">	 <embed src="banner.swf"	  quality="high"	  type="application/x-shockwave-flash"	  WMODE="transparent"	  width="1200"	  height="200"	  pluginspage="http://www.macromedia.com/go/getflashplayer"	  allowScriptAccess="always" /></object></noscript></div><table width="1000" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#9933FF">   <tr>	<td colspan="7" align="left" valign="top"><label>Search for:		<select name="select" id="select">		<option value="1">Name of customer</option>		<option value="2">Customer code</option>		<option value="3">######</option>		</select>		    		<input type="text" name="textsearch" id="textsearch" width="150px" />		  				<label> 				<input type="button" name="btntim" id="btntim" value="Search" />		<input type="reset" name="btnreset" id="btnreset" value="Reset" />		</label></td>	<td width="204" colspan="2" align="left" valign="top"><input type="button" name="them" id="them" value="Add/Cancel" />	  <input type="button" name="xoa" id="xoa" value="Delete" />	  <input type="button" name="sua" id="sua" value="Edit" /></td>  </tr>  <tr align="left" valign="top">	<td colspan="9"> </td>	</tr>  <tr align="left" valign="top">	<td><label>	  <input type="checkbox" name="checkall" id="checkall" />	</label></td>	<td >First and last name:</td>	<td>######:</td>	<td>Birth day:</td>	<td>Address:</td>	<td>Phone number:</td>	<td >Age:</td>	<td>Type:</td>	<td>Job:</td>  </tr>  <tr align="left" valign="top">	<td><input name="check" type="checkbox" id="check" value="1" /></td>	<td>	  <input name="name" type="text" id="name" width="200px" />	  </td>	<td><input name="######" type="text" id="######" size="4" maxlength="5" width="30px" /></td>	<td>	  <input type="text" name="date" id="date" maxlength="11" size="10" width="70px" />		</td>	<td><input name="address" type="text" id="address" value="" size="58" maxlength="58" width="257px" /></td>	<td><input type="text" name="phonenumber" id="phonenumber" width="70px" maxlength="13" size="13" /></td>	<td><input type="text" name="age" id="age" maxlength="3" size="3" width="40px" /></td>	<td><input name="type" type="text" id="type" size="20" maxlength="20" width="20px" /></td>	<td><input name="job" type="text" id="job" size="20" maxlength="20" /></td>  </tr>  <tr align="left" id="dongmoi" valign="top">	<td><input name="check" type="checkbox" id="check" value="1" /></td>	<td><input name="name" type="text" id="name" width="200px" /></td>	<td><input name="######" type="text" id="######" size="4" maxlength="5" width="30px" /></td>	<td><input type="text" name="date" id="date" maxlength="11" size="10" width="70px" /></td>	<td><input name="address" type="text" id="address" value="" size="58" maxlength="58" width="257px" s="58" /></td>	<td><input type="text" name="phonenumber" id="phonenumber" width="70px" maxlength="13" size="13" /></td>	<td><input type="text" name="age" id="age" maxlength="3" size="3" width="40px" /></td>	<td><input name="type" type="text" id="type" size="20" maxlength="20" width="20px"/></td>	<td><input name="job" type="text" id="job" size="20" maxlength="20" /></td><td><input type="button" value="ok"name="ok" id="ok" /></td>  </tr></table></form></body></html>

code xml:

<?xml version="1.0" encoding="utf-8" ?><quanlythuebao>	<khachhang makh="1">					<tenthuebao>Võ Hoàng Tuấn Linh</tenthuebao>					<sothuebao>01223456789</sothuebao>					<gioitinh>nam</gioitinh>					<ngaysinh>10/11/2002</ngaysinh>					<nghenghiep>Giám đốc</nghenghiep>					<tuoi>22</tuoi>					<socmnd>213131231311</socmnd>					<diachi>3/2 lang bac ho</diachi>					<hinhthuctb>tra truoc</hinhthuctb>	</khachhang>	<khachhang makh="2">					<tenthuebao>Bùi Trọng Khiêm</tenthuebao>					<sothuebao>01223456789</sothuebao>					<gioitinh>nam</gioitinh>					<ngaysinh>11/11/2011</ngaysinh>					<nghenghiep>Chủ tịch</nghenghiep>					<tuoi>22</tuoi>					<socmnd>213100223961</socmnd>					<diachi>3/2 lang bac ho</diachi>					<hinhthuctb>tra truoc</hinhthuctb>	</khachhang>	<khachhang makh="3">					<tenthuebao>Nguyễn Thị Kim Lý</tenthuebao>					<sothuebao>01223456789</sothuebao>					<gioitinh>nữ</gioitinh>					<ngaysinh>20/1/2001</ngaysinh>					<nghenghiep>Osin cao cấp</nghenghiep>					<tuoi>22</tuoi>					<socmnd>213199991</socmnd>					<diachi>3/2 lang bac ho</diachi>					<hinhthuctb>tra truoc</hinhthuctb>	</khachhang></quanlythuebao>

Link to comment
Share on other sites

Exactly where does the code stop working?
the first text field has data,but another text filed,them haven't data,i want to after the loop,output one text field and one data,and repeat until data of the end
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...