JavaScript onchange()
<p>i am new to JS and Programming..</p>

<p>i want to learn How to Implement onchange() in a text field in a form and capturing the value of that form field if the value is changed and i want to store that information in a text file, which i can create in php..i already have the text file in which i can use fopen and insert the value. but how to capture and store in some temp variable before writing it to text file.</p>

<p>i am including the code here..</p>

<p>This is from a update page which i am using to update this data...</p>

<p>thanx in advance..</p>

<pre><code>//function for multiple select field 
&lt;script&gt;
function Technology(value,state)
{
   if (value &gt; -1) {
      var input= new Array(value);
      var p;

      var techs = [

         &lt;?php
            $con = mysql_connect("localhost", "root");
            if (!$con)
            {
               die('Could not connect: ' . mysql_error());
            }
            mysql_select_db("root", $con);

            $load = mysql_query("SELECT tech from t_tech");
            while($arr = mysql_fetch_array($load))
            {
               echo "'".$arr[0]."',";
            }
         ?&gt;
      ].sort();
      var ele = document.getElementById("tech");

      if(ele.hasChildNodes())
      {
         var len = ele.childNodes.length;
         while(ele.childNodes.length - value &gt; 1)
         {
            ele.removeChild(ele.lastChild);
         }
      }
      var tech_array = new Array;
      &lt;?php
         for($i = 0;$i&lt;$_POST['tech_num'];$i++)
         {
            $p = $i+1;
            echo "tech_array[$i] = '".$_POST['tech'.$p]."';";
         }
      ?&gt;

      for (var i=len-1;i&lt;value;i++)
      {
         p= i+1;
         input[i] = document.createElement('div');

         if(state ==1 )
         {
            input[i].innerHTML = 'Technology' + p + ':  &amp;nbsp;&amp;nbsp; &lt;input type="text" name="tech' + p + '" id="tech' + p +'" size = 25 value="'+tech_array[i] +'"/&gt;';
         }
         else if (state == 0)
         {
            input[i].innerHTML = 'Technology' + p + ':  &amp;nbsp;&amp;nbsp; &lt;input type="text" value="" name="tech' + p + '" id="tech' + p +'" size = 25/&gt;';
         } 

         document.getElementById("tech").appendChild(input[i]);

         var techId = 'tech' + p;

         AutoComplete_Create(techId,techs);

      }           
}}
&lt;/script&gt;  
</code></pre>

<p>This is the form field:</p>

<pre><code>&lt;tr&gt; 
   &lt;td&gt;&lt;b&gt;
      Field1: &lt;select name="tech_num" id="tech_num" onChange="return Technology(this.value,0)"&gt; 
      &lt;?php 
         for ($i=0;$i&lt;=5;$i++) { 
            if ($i==0) 
               $temp = "&lt;option value=$i&gt; - &lt;/option&gt;"; 
            else if($i == $_POST['tech_num']) 
               $temp = "&lt;option value=$i selected='selected'&gt;$i&lt;/option&gt;"; 
            else $temp = "&lt;option value=$i&gt;$i&lt;/option&gt;"; 
               echo $temp; } 
      ?&gt; 
      &lt;/select&gt;
   &lt;/td&gt;
&lt;/tr&gt; 
&lt;/table&gt; 
&lt;div id="tech"&gt; &lt;/div&gt; &lt;table&gt;
</code></pre>
