1
Reply

How to get textbox entered value and with related row value in textarea using xml file in javascript

Venkat S

Venkat S

Jul 26 2011 2:31 AM
1.4k
Hi Friends,

I have a smal task i.e

I have textbox1 ,botton,textbox2 when i enter 21 value then i click button its get in sama row values in textbox2.

I have xml file like this

<DATAPACKET >  
  <ROWDATA>
  <R_ID>101</R_ID>
  <R_NAME>R-12</R_NAME>
  <R_TEMP>4.266</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>20</R_ID>
  <R_NAME>R-22</R_NAME>
  <R_TEMP>4.266</R_TEMP>
  <R_COLOR>Green</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>21</R_ID>
  <R_NAME>R-32</R_NAME>
  <R_TEMP>4.266</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>104</R_ID>
  <R_NAME>R-134A</R_NAME>
  <R_TEMP>4.246</R_TEMP>
  <R_COLOR>Light Blue</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>21</R_ID>
  <R_NAME>R-290</R_NAME>
  <R_TEMP>4.246</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>31</R_ID>
  <R_NAME>R-401A</R_NAME>
  <R_TEMP>4.246</R_TEMP>
  <R_COLOR>Pink</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>32</R_ID>
  <R_NAME>R-401B</R_NAME>
  <R_TEMP>4.264</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>108</R_ID>
  <R_NAME>R-402A</R_NAME>
  <R_TEMP>4.426</R_TEMP>
  <R_COLOR>Light Greem</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>129</R_ID>
  <R_NAME>R-402B</R_NAME>
  <R_TEMP>4.266</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>110</R_ID>
  <R_NAME>R-404A</R_NAME>
  <R_TEMP>4.246</R_TEMP>
  <R_COLOR>Orange</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>121</R_ID>
  <R_NAME>R-407A</R_NAME>
  <R_TEMP>4.267</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>122</R_ID>
  <R_NAME>R-408A</R_NAME>
  <R_TEMP>4.267</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>113</R_ID>
  <R_NAME>R-409A</R_NAME>
  <R_TEMP>4.267</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>134</R_ID>
  <R_NAME>R-407C</R_NAME>
  <R_TEMP>4.264</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
  <ROWDATA>
  <R_ID>115</R_ID>
  <R_NAME>R-410A</R_NAME>
  <R_TEMP>4.426</R_TEMP>
  <R_COLOR>White</R_COLOR>
  </ROWDATA>
</DATAPACKET > 
 then i try this hear i get all values
function gettxt() {
 
  results = new Array;
  var searchterm = document.getElementById("searchme").value;
  if (searchterm == null || searchterm == "") {
  alert("Enter textbox value");
  return false;
  }
  var istrlen1 = searchterm.length;
  var tempname1;
  if (istrlen1 == 1) {
  tempname1 = searchterm;
  }
  if (istrlen1 == 2) {
  tempname1 = searchterm;
  }
  if (istrlen1 == 3) {
  tempname1 = searchterm;
  }
  if (istrlen1 == 4) {
  tempname1 = searchterm;
  }
  for (i = 0; i < x.length; i++) {
  var name = x[i].getElementsByTagName("R_ID")[0].firstChild.nodeValue;
  var name1 = x[i].getElementsByTagName("R_NAME")[0].firstChild.nodeValue;
  var exp = new RegExp(tempname1, "i");
  if (name.match(exp) != null) {
  y = y + 1;
  results.push(name1);
  }
  }
  textbox2.value = results;   
  }

I try the above code hear small problom when i enter 21 and click button its display 21,121,123... related values i dont want like that

For example textbox1=21 buttonclick textbox2=R-32,r-407A,r-408A like that i dont want like that

I want textbox1=21 buttonclick textbox2=R-32 only in same row value
please any one knows well in js please resolve my problom

Answers (1)