2014-12-23 183 views
0

我有一個下拉菜單。當選擇該選項時,它會調用ajax腳本並根據選擇傳遞來自另一個php頁面的值。 我想在paypal按鈕上點擊時將該值傳遞給paypal賬戶。將ajax值傳遞給paypal

阿賈克斯

function showUser(id) { 
    //get the selected value 

    //make the ajax call 
    $.ajax({ 
     url: 'ajax_cat.php', 
     type: 'GET', 
     data: {option : id}, 
     success: function(data) { 
      document.getElementById('cat_cost').innerHTML =data; 

     } 
    }); 
} 

形式

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
    <div > 
    <select name="category" class="choose_list" onchange="showUser(this.value)" > 
     <?php 
     $query= "SELECT * FROM requests 
        WHERE cat_action='Waiting'" ; 
     $result= mysql_query($query); 

     while($row = mysql_fetch_assoc($result)){ 
      echo '<option value="'.$row['package_id'].'">'.$row['cat'].'</option>'; 
     } 
     ?>  
    </select> 
</div> 

<div id="cat_cost"> 

</div> 
<input type="hidden" name="cmd" value="_xclick" /> 
     <input type="hidden" name="business" value="[email protected]" /> 
     <?php /*?><input type="hidden" name="item_name" value="<?php echo $type; ?>" /><?php */?> 
     <input type="hidden" name="item_number" value="<?php ?>" /> 
     <input type="hidden" name="amount" value="<?php ?>" /> 
     <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> 
     <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> 
</form> 

回答

0

使這個HTML

<select name="category" class="choose_list" id="select_choose_list"> 
    <?php 
    $query= "SELECT * FROM requests WHERE cat_action='Waiting'" ; 
    $result= mysql_query($query); 
    while($row = mysql_fetch_assoc($result)) { 
     echo '<option value="'.$row['package_id'].'">'.$row['cat'].'</option>'; 
    } 
?> 
</select> 
現在

在AJAX請求

$('#select_choose_list').change(function(){ 
     $.ajax({ 
      type: 'GET', 
      url: 'ajax_cat.php&id=' + $('#select_choose_list').val(), 
      success: function(data) { 
       $('#cat_cost').html(data); 
      } 
     }); 
    }); 

試試:)

+0

ajax從ajax_cat.php.it傳遞值ok.but我想要做的是將這些值傳遞給paypal。 – KT1

+1

+1

$('#paypal_amt')。val(data); //像這樣 –