I am new to JavaScript so please be understanding of my situation.
I have created a simple HTML form which includes a drop down menu (to select quantity of item) and a submit button (to add to a cart).
Once submitted the results of the form are displayed in a table on the webpage.
So far with my code I can display the results of the form options.
However, I need to replace the quantity with the variable result for “qtytoy1”.
Here is my code.
function addToy1New()
{
var i = document.getElementById("qty_toy1");
var qtytoy1 = i.options[i.selectedIndex].text;
var htmlTagString="<table width=\"100%\" border=\"0\">"
+" <tr>"
+" <td>Optimus Prime</td>"
+" <td> x 1</td>"
+" <td>$26.99</td>"
+" </tr>"
+" <tr>"
+" <td></td>"
+" <td>Total:</td>"
+" <td>$26.99</td>"
+" </tr>"
+"</table>";
document.getElementById("toy1_add").innerHTML=htmlTagString;
document.getElementById("toy1_test").innerHTML=qtytoy1;
}
How can I replace “$26.99” with my variable “qtytoy1”?
I am pretty sure there are better ways around this method. Please share if you think so but make sure it is understandable for a novice such as myself. 🙂
1 Answer