我不知道这是否可能,但我认为值得一提。基本上我需要将Array
个值从php
网页传递到基础JQuery
。
Array
包含database
中所有用户的列表,我想与这些用户填充dropdown
。
这是我的php
页面:(使用html
)
<form action="<?the_permalink()?>" method="post">
<div id="summary">
<?php wp_dropdown_users(array('name' => 'CMP Member') ); ?>
<table id="ordertable">
<tr><th>Product</th>
<th>Quantity</th>
<th>Bulk</th>
<th>Options</th>
</tr>
</table>
<!-- Comments Box -->
Comments<br/>
<textarea name="comments"></textarea><br/>
<input name="product_list" id="products_field" type="hidden" value="<?= isset($_POST['product_list'])?$_POST['product_list']:'' ?>">
Next Day Delivery <input type="checkbox" name="next-day-delivery" value="yes" />
<input type="submit" value="Confirm Order" class="confirmBtn"/>
</div>
</form>
这是我的JQuery
$this = $(this);
//If the cookie exists get a reference to the array it contains (productArray)
if($.cookie('order_cookie') != undefined){
productArray = JSON.parse($.cookie('order_cookie'));
$.cookie('order_cookie', JSON.stringify(productArray), { expires: 1, path: '/' });
$('#products_field').val(encodeURIComponent($.cookie('order_cookie')));//Add to hidden field
}
//Reference to the order table
var ordertable = document.getElementById("ordertable");
//Loop through the Array and display in the table
for(var i = 0; i < productArray.length; i ++){
//Check if a dropdown is required in bulk order...
if(productArray[i].bulk == 'true'){
var bulk = "<select><option value='...'>...</option></select>";
}else{
var bulk = "";
}
var productRow;
productRow = '<tr>';
productRow += '<td>' + productArray[i].stockCode + '</td>';
productRow += '<td>' + productArray[i].quantity + '</td>';
productRow += '<td>' + bulk + '</td>'; <-- Want to put dropdown here!
productRow += '<td><input type="button" value="-" class="removeBtn"/>'
productRow += '<input type="button" value="+" class="addBtn"/>'
productRow += '<input type="button" value="Delete" class="deleteBtn"/></td>'
productRow += '</tr>'
$('#ordertable tr:last').after(productRow);
}
如果有人对如何做到这一点有任何建议,我会很感激