How to change a javascript function's parameter from callback function
<p>I have an HTML input element generated by the server and it looks like this:</p>

<p><em><strong>HERE IS THE SERVER SIDE</em></strong></p>

<pre><code>"&lt;input id='" + cRoadList.getRoadListNumber() + ",start_km' style='' type=\"text\" value='"+ cRoadList.getStartKm() + "' onkeypress='handleRoadListDataUpdate(\""+cRoadList.getStartKm()+"\")'
</code></pre>

<p>As you see the attrbutes of the input element are generated dynamically but that is not the case so let's simplify it by putting some static data like this:</p>

<pre><code>"&lt;input id='myID' style='' type=\"text\" value='100' onkeypress='handleRoadListDataUpdate(\"100\")'
</code></pre>

<p>The most important part of this HTML input element is the <strong>onkeypress</strong> event which calls the function <strong>handleRoadListDataUpdate</strong></p>

<p><em><strong>HERE IS THE CLIENT PART</em></strong></p>

<pre><code>function handleRoadListDataUpdate(oValue) // The function accpets the old value of the *input* element
{
   var event = handleRoadListDataUpdate.caller.arguments[0] || window.event ;

   var keyPressed = event.keyCode;
   if(keyPressed == 13)
   {
        var roadListNumber = event.target.id.split(",")[0];
        var inputId        = event.target.id.split(",")[1];
        var nValue         = event.target.value;

        if(nValue != oValue)
        {
               var userAction = confirm("Are you sure you want to change this value?\nPrevious value:   " + oValue + "\nNew value: " + nValue);
               if(userAction == true)
               {   
                    var url = "/GBS/RoadListController";
                    var params = "type=updateRoadList&amp;roadListNumber=" + roadListNumber + "&amp;updateData="+inputId + "&amp;newValue="+ nValue;
                    dhtmlxAjax.post(url,params,function(loader) 
                    {
                            var xmlDoc = loader.xmlDoc.responseXML;

                            var sqlResponse = xmlDoc.documentElement.getElementsByTagName("response");
                            var result      = sqlResponse[0].getAttribute("value");

                            if(result == "sql_error")
                            {
                                alert("The operation could not be completed because of an network error!");
                                event.target.value = oValue;
                            }
                            else if(result == "sql_success")
                            {
                                alert("The operation completed successfully!");
                                //Change the parameter oValue of the parent function
                            }  
                    });
               }
               else
               {
                   event.target.value = oValue;
               }
        }     
   }    
}
</code></pre>

<p>Basically this function is about updating (using ajax) the database with the new value the user enters inside the <em>input</em> element and press key <em>Enter</em>. <strong>If the parameter oValue is different than the parameter in the input element an ajax request is made so the database can be updated with the new value.</strong></p>

<p>When the operation completes we have the new value in the <em>input</em> element (which is entered by the user) <strong>but the problem is that if he press Enter again the function get executed AGAIN because its parameter oValue is not changed with the new value.</strong></p>

<p>So my very question is: </p>

<p>How to change the handleRoadListDataUpdate() function's parameter <strong>oValue</strong> to become the same as <strong>nValue</strong> so if the user press Enter by accident the function does not execute the ajax part again?</p>

<p>P.S.</p>

<p>Please no jQuery code! Only pure javaScript!</p>
