nestorvaldez Posted October 28, 2006 Share Posted October 28, 2006 Im working with a MySql Database with PHP, but, right now I need to make some calculations in the client area, I mean the system must give the results before to send to the database, I've got it using Javascript. This is just the explanation what Im doing... My problem is that I have some decimal(3.2) fields in MySql with NULL. I want Java script in the calculation take the null value not like a 0. This is because I'm making some avg calculations, and I have two Fields to make the avg calculation, if the fields are >=0 it will promediate considering this field if some of the fields is not 0 (NULL. it take the value from DB) it will not considerate it to promediate.EX1. REG_PRA1 =80 REG_PRA2 =90 In this case it must calc (80+90) /2 = 85EX2. REG_PRA1 =80 REG_PRA2 =0 In this case it must calc (80+0) /2 = 40EX3. REG_PRA1 =80 REG_PRA2 =NULL In this case it must calc (80+90) /1 = 80Im using this code: the code is working well, the problem is takin the value (0 or null) from the DB) it take both (0 and null) like 0.0 I need to solve it to make the correct average. var reg_pra1 = document.Actualizar.reg_pra1.value; var reg_pra2 = document.Actualizar.reg_pra2.value; var count=0; var sum=0; if(reg_pra1>=0){ count=count+1; sum = reg_pra1 * 1; } if(reg_pra2>=0){ count=count+1; sum = (sum * 1) + (reg_pra2 * 1); } if(sum>0){ var prompra = sum/count; prompra.toFixed(1) document.Actualizar.reg_promp.value = prompra.toFixed(1); } Quote Link to comment Share on other sites More sharing options...
fenway Posted October 28, 2006 Share Posted October 28, 2006 The question is how you get back NULL vs zero from your DB to begin with. Quote Link to comment Share on other sites More sharing options...
nestorvaldez Posted October 28, 2006 Author Share Posted October 28, 2006 so, how is it? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 28, 2006 Share Posted October 28, 2006 I'm confused... .value in JS for an INPUT will never be NULL. 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.