javascript - Multiplying two variables (JS) displaying on input -
I have an exercise where I need to display objects, prices, quantity, value etc. ... multiply me Having difficulty doing the Quantity value is my code with input and options given below which I am displaying, and the script function below will be greatly appreciated!
& lt; Body & gt; & Lt; Label & gt; Select item & lt; / Labels & gt; & Lt; Select onChange = "GetPrice (this)" & gt; & Lt; Options & gt; & Lt; / Options & gt; & Lt; Options & gt; Tomatoes & lt; / Options & gt; & Lt; Options & gt; Lettuce & lt; / Options & gt; & Lt; Options & gt; Potatoes & lt; / Options & gt; & Lt; Options & gt; Carrot & lt; / Options & gt; & Lt; Options & gt; Elephant & lt; / Options & gt; & Lt; / Select & gt; & Lt; Br / & gt; & Lt; Label & gt; Price & lt; / Labels & gt; & Lt; Input type = "text" id = "value" /> & Lt; Br / & gt; & Lt; Label & gt; Quantity & lt; / Labels & gt; & Lt; Choose onChange = "GetFull (this)" & gt; & Lt; Options & gt; & Lt; / Options & gt; & Lt; Options & gt; 1 & lt; / Options & gt; & Lt; Options & gt; 2 & lt; / Options & gt; & Lt; Options & gt; 3 & lt; / Options & gt; & Lt; Options & gt; 4 & lt; / Options & gt; & Lt; Options & gt; 5 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Br / & gt; & Lt; Label & gt; Total $ & lt; / Labels & gt; & Lt; Input type = "text" id = "value of quantity" / & gt; & Lt; Script type = "text / javascript" & gt; Var veggy = {}; Veggie ["tomatoes"] = 5.99 vegji ["lettuce"] = 7.66 veggie ["potato"] = 4.52 veggie ["carrot"] = 2.13 veggie ["artichoke"] = 10.58 function getprice (select) {document.getElementById ( "value"). Value = vegji [select.value]; } Var quantity = {}; Quantity ["1"] = 1 quantity ["2"] = 2 volume ["3"] = 3 quantities ["4"] = 4 quantities ["5"] = 5 function getFull {select} {document.getElementById} ("Quantity Value"). Value = (quantity [select.value] * veggy [select.value]); } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;
The problem is that you get value from veggy
value
.
function getFull (select) {document.getElementById ("quantityPirice"). Value = (quantity [select.value] * Veggy [select.value]); }
Here you are passing the references to quanntity
, but you have value
form item
object < Please enter ID
for SelectItems / P>
only your first select
.
& lt; Select id = "veggy" onChange = "getPrice (this)" & gt;
and like getFull
getFull (select) {var vegSelect = document.getElementById ('veggy'); Document.getElementById ("quantityPrice"). Value = (quantity [select.value] * (veggy [vegSelect.value])); }
Comments
Post a Comment