2014-01-13 13 views
0

我有下面的代碼運行良好的下拉菜單,但你可以看到第二個值(next_val = 250f3)是靜態的。我想使動態應該改變點擊。PHP阿賈克斯傳遞兩個值 - 1個下拉菜單中的2個按鈕

<script type="text/javascript"> 

function showUser(str) 
{ 
    if (str == "") 
    { 
     document.getElementById("txtHint").innerHTML = ""; 
     return; 
    } 
    if (window.XMLHttpRequest) 
    { 
     xmlhttp = new XMLHttpRequest(); 
    } 
    else 
    { 
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    xmlhttp.onreadystatechange = function() 
    { 
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
     { 
      document.getElementById("txtHint").innerHTML = xmlhttp.responseText; 
     } 
    } 
    xmlhttp.open("GET", "productlistajax.php?q=" + str + "&next_val=250f3", true); 
    xmlhttp.send(); 
} 
</script> 

這裏是下拉菜單代碼。

<select id="maxDaysSinceAdded" name="shorting" onchange="showUser(this.value)"> 
    <option selected='selected' value="1">Most Recent</option> 
    <option value="2">Lowest Price</option> 
    <option value="3">Highst Price</option> 
</select> 

如何使用按鈕來傳遞值以上住下拉菜單

<button type="button" name="buttonpassvalue" onclick="">Value</button> 

感謝

+0

我不明白你的價值,你希望把next_val。 – thelr

回答

0

您對select tag變化事件調用showUser()。因此,在這種情況下,您必須在發送ajax請求之前從腳本本身讀取值。

您可以通過修改代碼

var buttonValue = document.getElementsByName('buttonpassvalue').item(0).value; 
xmlhttp.open("GET", "productlistajax.php?q=" + str + "&next_val=" + buttonValue, true); 
+0

感謝卡蘭......我們可以調用showUser的單獨的值(STR,strsecond)......像showUser(str.this.value),然後第二showUser(strsecond.this.value) – Reel

+0

您可以傳遞兩個參數的功能..但是,我真的不明白你想說什麼?請詳細說明!!! – ghopst