Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,852 members, 8,004,057 topics. Date: Saturday, 16 November 2024 at 07:50 AM |
Nairaland Forum / Science/Technology / Programming / Can Anybody Debug This Javascript? (1178 Views)
Someone Explain This Javascript Snippet / Please Help Debug This Javascript Program / When Your Brain Throws Stackoverflow Error - Debug This JAVA Code If You Can (2) (3) (4)
Can Anybody Debug This Javascript? by nnamokenna(m): 10:37pm On Sep 20, 2016 |
Hi all. I have this JavaScript code that has been giving me headache. The code is this:
The Total field should give the total of the values in the input boxes while Total1 should give the total of the values in the input boxes, but when you change the value of "Additional Menu Items" field, the field should be multiplied by 1.5 (that is 1.5 x the value). It is giving NaN presently. I have tried everything but can seem to get it to work. Any help would be appreciated. Thanks PS: I attached the file
|
Re: Can Anybody Debug This Javascript? by Nobody: 11:27pm On Sep 20, 2016 |
The reason is because some of the values you are trying to add up is returning NAN. So change this line total1 += parseFloat(ele1.value);to if(ele1.value !==undefined) {total1 += parseFloat(ele1.value);}and that should do the trick 1 Like |
Re: Can Anybody Debug This Javascript? by nnamokenna(m): 11:47pm On Sep 20, 2016 |
dhtml18: Thank you for your time but I have tried that before without success. Whatever value you put in the "Additional Menu Items" should be multiplied by 1.5 before being summed with the other values in the other fields to give Total1. So in essence, the value of Total1 should be more than Total but with this way it (Total1) is being reduced by the value you put in "Additional Menu Items". |
Re: Can Anybody Debug This Javascript? by Nobody: 12:00am On Sep 21, 2016 |
I have attached the entire correction something to this post. Works fine at my end, even in the EVIL INTERNET EXPLORER. If there is any other thing, it might be a logical problem.
|
Re: Can Anybody Debug This Javascript? by Kodejuice: 3:43am On Sep 21, 2016 |
replace ' var temp = coll[i] ' with 'var temp = coll[i].value', thats the source of the NaN, i haven't ran it yet, i just used my built in debugger. the error occured when you multiplied an html element with a numerical value, so ur browser dey complain. Error => var temp1 = temp * add_menu_item1 1 Like |
Re: Can Anybody Debug This Javascript? by nnamokenna(m): 7:16am On Sep 21, 2016 |
Thank you very much @dhtml18 and @Kodejuice for your assistance. It is working now. |
Re: Can Anybody Debug This Javascript? by Nobody: 8:08am On Sep 21, 2016 |
You are welcome. |
(1) (Reply)
Video: DJ Kaywise – Caro Ft. Tekno & Falz / Mistake Beginner Programmer Make / Need A Person Who Can Teach Me Programming
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24 |