How to add input field value using jQuery

I have an input box as shown below

 <input name="update_price" type="text" id="update_price" value="£" size="8" 
        maxlength="8" />

I would like to get some price value from the value of the selection field and add it after the £ sign, as this is achieved in jquery,

  <form>
                <select name="select" id="select">
                  <option>Select your pizza</option>
                  <option value="6.65">NY, 10&quot;, £6.65</option>
                  <option value="8.95">NY, 12&quot;, £8.95</option>
                  <option value="11.95">NY, 16&quot;, £11.95</option>
                  <option value="3.45">Chicago, 7&quot;, £3.45</option>
                  <option value="6.65">Chicago, 10&quot;, £6.65</option>
                  <option value="8.95">Chicago, 12&quot;, £8.95</option>
                  <option value="11.95">Chicago, 16&quot;, £11.95</option>
                  <option value="19.95">Chicago, Beast 24&quot; x 18&quot;, £19.95</option>
                 </select>
         </form>



    $(function()
    {
   $('#select').change( function() {

    $('input[name=update_price]').val($("#select :selected").val() );
  });
   });

it works with the code above, but the £ sign disappears, any help would be appreciated.

+5
source share
4 answers

In the past, I used a background image in an input field for a currency symbol. In this way, the symbol can look beautiful, left-aligned (while the value is right-aligned), and it does not interfere with the calculations.

Hope that helps

+4
source

? , , javascript UTF-8 ( bom. notepad ++ )

Btw , , , . .

$(function() {
  $('#select').change(function() {
    $('#update_price').val("£" + $(this).val());
  });
});
+4

.

<option value="€ 6.65">NY, 10&quot;, £6.65</option>

. Nicer :

$('input[name=update_price]').val("€"+$("#select :selected").val() );

, , €:)

//

<input type='hidden' name='shopping_cart_value' value='0'>

$('input[name=update_price]').val("€"+$("#select :selected").val() );
$('input[name=shopping_cart_value]').val($("#select :selected").val() );
+2
+2

All Articles