javascript - JS change input value -


my problem is: have 2 input boxes 1 code , 1 price:

<input class="style" name="code" id="code" type="text"> <input class="style" name="price" id= "price" type="text" value="&euro; 15,00" readonly="readonly"> 

now want change price code (like check code array [code1][code2]. result code1 = price/2 , code2 = price/4 ) want check script in real time or befor post (on submit). this possible when yes how? or there better way ?

i have:

while(true)  {     var code = document.getelementbyid("code").value;      var codes = new array("promo1", "promo2");      (var i=0; i<codes.length; i++) {          if (codes[i] == code) {             document.getelementbyid("price").value = "5";         }            } } 

and input fields in form-field value doesnt change, why ? dont have change in real time ok if post sends new value...any solutions/better ideas/hints ? know there jquery better approach shouldn't problem js.

fiddle link:
jsfiddle.net/vicr/4mtbr

this can obtained in many ways, specially if 1 takes use of libraries or frameworks, pure javascript should done so:

while(true) {  var code = document.getelementbyid("code").value  //now check valid code in sort of map or array  //remember javascript supports string indexed arrays such arr["#45"]  if(code == validatorfunctionorcode) { //obviously pseudo   document.getelementbyid("price").value = "your corresponding price code"  } } 
  • this checked dynamically , before hit submit button.

with said recommend angular.js since supports databinding (example - databinding )


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -