stockton Posted April 25, 2007 Share Posted April 25, 2007 Please tell me why I get a NaN returned in my Javascript from :- IssuedValue = document.getElementById("IssuedValue").value; OutstandingValue = document.getElementById("OutstandingValue").value; document.getElementById("IssuedValue").value = IssuedValue + OutstandingValue; document.getElementById("IssuedValue").value ends up being a NaN, why? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2007 Share Posted April 25, 2007 See what those two values you're trying to add actually are. Quote Link to comment Share on other sites More sharing options...
stockton Posted April 26, 2007 Author Share Posted April 26, 2007 Do you have a recommendation on how I should identify what these values are? Those two values are ex a MSSQL database. The web page calls Ajax to repopulate its fields by calling a PHP program. This step works fine. Next step is when the user clicks an install button Ajax is again called which in turn calls a PHP script on the server to update the database and on return from the PHP to Ajax I wish to alter those two fields so that I can call a Javascript function to print the displayed data. However at this point the data on the screen is what is going to happen and I need this to change(the database has been updated) to what has happened. IssuedValue needs to be updated to what was altered in the database. BTW The database is reflecting the correct information. So now the only issue is to get the printout to reflect the correct data. Quote Link to comment Share on other sites More sharing options...
stockton Posted April 26, 2007 Author Share Posted April 26, 2007 I have added an alert to the scenario giving the following:- my Ajax as follows:- function handleIssueTicketsResponse() { if(http.readyState == 4 && http.status == 200) { var IssuedValue = document.getElementById("IssuedValue").value; var OutstandingValue = document.getElementById("OutstandingValue").value; alert("Before IssuedValue: "+IssuedValue+" OutstandingValue: "+OutstandingValue); and the alert reports both IssuedValue as well as OutstandingValue as undefined. Therefore the problem lies in the getElementById() but is the problem my use of getElementById() or is the problem in my definition of these fields in my web page. These fields are defined as:- <div style="position:relative;" id="IssuedValue";><b>Issued value.</b></div> <div style="position:relative;" id="OutstandingValue";><b>Outstanding value.</b></div> Quote Link to comment Share on other sites More sharing options...
fenway Posted April 26, 2007 Share Posted April 26, 2007 They're DIVs? That's less than ideal, you should put them into hidden INPUT fields so you don't have to worry about formatting issues. Otherwise, you'll be dealing with innerHTML garbage. Quote Link to comment Share on other sites More sharing options...
stockton Posted April 26, 2007 Author Share Posted April 26, 2007 Thank you. As you say innerHTML solved the immediate problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.