Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dears , i need support in JavaScript code, this code working with span id only i want this result showing in hidden input in html, can anybody help me.

html code :

HTML
<input type="text" id="item-price">


javascript code :
JavaScript
   var basePrice = 0;

   $(document).ready(function() {
       $(".calculate").change(function() {
           newPrice = basePrice;
           $(".calculate option:selected").each(function() {
               newPrice += $(this).data('price')
           });
           $("#item-price").val(newPrice.toFixed(2));
    });
});


What I have tried:

i have tried to change .val to .html but nothing happend.
Posted
Updated 5-Nov-18 0:39am
v4
Comments
F-ES Sitecore 2-Nov-18 6:20am    
set the type of your input to "hidden", not "text"
Sinisa Hajnal 5-Nov-18 6:36am    
Don't do hidden, do visibility: hidden - display: none will not be rendered on the page and you will not be able to assign the value client side.

1 solution

HTML
<input id='item-price' visibility='hidden' value='' />


Note that type='text' is default and you can take it out. visibility hidden, as opposed to display: none will be rendered and will affect your layout. I suggest you use position: absolute and put it somewhere outside the screen (top: -1000px; left: -1000px), but this is optional
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900