JavaScript - Parsefloat?
I use the below parseFloat function to get the last numbers from the below id but I would like to also get the middle number between the "_" and call it
"part_price". How can I extract those numbers? Code: id="PROD_1_55.55_133.50" item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) part_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) Similar Tutorialshere is the code, it is supposed to calcualte the total of the books and display them but when displayed all i get is NAN (only works in ie). This is part of my course work so please help <html> <head> <title>Arrays</title> <script type="text/javascript"> function show_prompt(){ document.write("<h2>Arrays</h2>") var book = new Array() for (a = 0; a <= 10; a++){ book[a]=prompt('Enter book name') } var price = new Array() for (i = 0; i <= 10; i++){ price[i]=prompt('Enter price of item named :'+book[a]); document.write(' <b>Name:</b> '+ book[a] + " <b>Price:</b> "+price[i]+'<br/>'); } var total = parseFloat(price[i]); document.write( 'total:' + total + '<br/>') } </script> </head> <body onload = "show_prompt()"> </head> </html> Hello, As a novice, I'm not sure which one to use though. I'm trying to do a calculation with numbers in JavaScript using variables, particularly adding variables. Any guided understanding of this concept is welcome. For example: Code: n = parseint(n) document.write(n += m) |