tags:

views:

105

answers:

1

Hi,

I' trying to add a text of select box and the some text from a form into a hidden field,I can get the text of a select box but I can get the required text from form, can anyone help please.

  <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>

        <form id="toppings">
          <span class="descriptionsPizza">EXTRA CHEESE</span>
            <input name="minus1" type="button" class="button minus" id="minus1" value=" - " />
            <input name="textfield1" type="text" id="textfield1" class="valfield" size="2" maxlength="2" value="0" />
            <input name="add1" type="button" class="button add" id="add1" value=" + " />

            <span class="descriptionsPizza">HAM</span>    
            <input name="minus2" type="button" class="button minus" id="minus2" value=" - " />
            <input class="valfield" name="textfield2" type="text" id="textfield2" size="2" maxlength="2" value="0"/>
            <input name="add2" type="button" class="button add" id="add2" value=" + " />

            </form>


      $(function()
         {
       //functions to change the quantity field by pressing the + and - buttons

      // add buttons
     $(".add").click(function(){
     var $this = $(this);
     var quantity = parseInt($this.siblings(".valfield").val(), 10) + 1;
    $(this).siblings(".valfield").val(quantity);


   });

   // minus buttons
   $(".minus").click(function(){
   var $this = $(this);
   var quantity = parseInt($this.siblings(".valfield").val(), 10) - 1;
   if(quantity < 0) quantity = 0;
   $(this).siblings(".valfield").val(quantity);

 });

      $('input[name=my-add-button]').click(function() {

    var randomNumber = Math.floor((Math.random() * 9000) + 100);
        $('input[name=my-item-id]').val(randomNumber);
    $('input[name=my-item-name]').val( $("#select :selected").text() );
    $('input[name=my-item-price]').val( $('#update_price').val() );
    });

so I need to add the toppings name (the text in the span tag) if the quantity of that topping is greater than 0 add the text in the span into the hidden field as well as the selected text box.

thanks for any help.

A: 
var descriptionsPizza = [];
$("input.valfield").each(function(){
    if ($(this).val() > 0){
        descriptionsPizza.push( $(this).prevAll(".descriptionsPizza").text() );
    }
});

$("hiddenInputSelector").val(descriptionsPizza.join(' '));
T B