简体   繁体   中英

How to get the value from textbox & dropdown without submit

I want to pass the value of product id, product name, textbox & drop down to 'addtocart.php' page. Only values I managed to get are id & name. If I use form for these then values of product id & name are not submitting. Can anyone help sending values of textbox & dropdown as well?

while ($row = @ mysql_fetch_array($results)){

                print
                "<div class= 'item'>" .
                "<p>Product id ".$row["id"]."</p>".
                "<p><img src=".$row["image_location"]." class='masterTooltip' id='b7' title='Double click on image to make as favorite' ondblclick='openlink({$row["id"]})'></p>".
                "<p>&pound".$row["price"]."</p>".
                "<p>".$row["name"]."</p>".
                "<p>".
                "Qty:&nbsp;&nbsp;&nbsp;<input type='text' id='quantity' name='quantity' style='width: 20px; height:14px;'>".
                "&nbsp;<select name='type'>".
                "<option value='KiloGrams'>KiloGrams</opstion>".
                "<option value='Bunch'>Bunch</option>".
                "</select>".
                "<p>".      
                "<a href='addtocart.php?id={$row["id"]}&name={$row["name"]}' class='button' id='b1'> Buy Now</a>".
            //  "&nbsp;&nbsp;<a href='addtofavorite.php?id={$row["id"]}&name={$row["name"]}' id='heart'></a>".
                "</p>".
                "</div>";

对于那些不在任何其他输入中但要发送到服务器的字段,您需要使用<input type='hidden' name='your_field_name' value='your_field_value' />表格。

You want to use ajax, I don't know if used it before but it works like this; First you need to listen change event then send request to server;

$( "#type" ).change(function() {
 $.ajax({
      url: "test.php",
      context: this.val()
       }).done(function() {
            alert("it worked");
            });
       });

I hope you I could express it well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM