jquery - append form field to url -


i'm trying append value (quantity) text input field url. of course can't work.

what i've got is:

<form class="formproduct" id="formproduct" action="#" method="post"> <input type="text" name="quantity" id="formproductquantity" value="{{ product.stock.minimum }}" /> // text field quantity <a class="button blue opener" href="" title="{{ 'add cart' | t }}"><span>{{ 'add cart' | t }}</span></a> // submit button </form>  <script>  var addurl = "http://shop.com/cart/add/123456/?quantity="; // 123456 product id  asset("#formproduct");  function asset(product){      $(product + " input#formproductquantity").val("1");     $(product + " #formproductquantity").keyup(function () {          var val = $(product + " input#formproductquantity").first().val();     });      $(product + " .opener").click(function() {            var val = $(product + " input#formproductquantity").first().val();                // go page               window.location.href = addurl + val;      });  }  </script> 

so try pass quantity filled in form pass http://shop.com/cart/add/123456/?quantity=100 example. code above found on forum can't work.

any more welcome

update

ok thx here got work. comments or modifications still more welcome. function code looks this:

<script type="text/javascript">  var addurl = "http://shop.com/cart/add/123456/?quantity="; // 123456  product id   jquery(document).ready(function(){   asset("#formproduct");   });  function asset(product){  jquery(product + " input#formproductquantity").val("1"); jquery(product + " #formproductquantity").keyup(function () {      var val = jquery(product + " input#formproductquantity").first().val(); });  jquery(product + " .opener").click(function(event) {   event.preventdefault();    $.get($(this).attr('href'), function(data, status) {        var val = jquery(product + " input#formproductquantity").first().val();            // go page           window.location.href = addurl + val;   $( "#dialog" ).dialog( "open" );           return false;    });  })} 

you trying add javascript submit button run through javascript form still submitted, therefore window.location.href won't take place. need add

return false;

to end of asset() function:

$(product + " .opener").click(function() {     var val = $(product + " input#formproductquantity").first().val();      // go page     window.location.href = addurl + val;     return false; }); 

this stop form submitting, allowing window.location.href redirect required.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -