[英]Posting a form using AJAX
你知道如何發送我的單選按鈕名稱嗎?
myAjaxPostrequest.send(parameters);
參數可以是這樣的:
var answername=document.getElementById('option1').name;
var parameters=answername;
? 此代碼用於使用ajax發布表單
我的php頁面需要點擊radiobutton的名稱
我嘗試了這個代碼,除了插入數據庫之外,它可以正常工作。 這意味着參數是問題
我要插入的是位於radiobutton名稱的brakects之間的數字。
當我在沒有AJAX的情況下發布表單但是現在我無法發送radiobutton的名稱時,我可以這樣做
任何關於我可以作為函數myAjaxPostrequest.send(parameters);
參數發送的線索myAjaxPostrequest.send(parameters);
?
<form id="Question1" method="post">
<br />
<P> The sky color is..
</P><img border="0" src="images/wonder.png" width="94" height="134"/><br /><br /><br />
<input type="radio" id="option1" name="answer[1]" value="correct!" onclick="submitFormWithAjax();"/> blue
<br />
<input type="radio" id="option1" name="answer[1]" value="false!" onclick="submitFormWithAjax();"/> red
<br />
<input type="radio" id="option1" name="answer[1]" value="false!" onclick="submitFormWithAjax();"/> green
<br />
<input type="radio" id="option1" name="answer[1]" value="false!" onclick="submitFormWithAjax();"/> white
</form>
通過以下方式,您可以將參數傳遞給ajax調用:
var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
你會用:
var checkedRadio = document.getElementsByName('nameOfRadios');
var isChecked = checkedRadio.checked
因此,要獲取已檢查無線電的值,請執行以下操作:
var checkedRadio = document.getElementsByName('nameOfRadios');
var isChecked = checkedRadio.checked;
var checkedValue;
for (var i=0; i<checkedRadio.length; i++) {
if (checkedRadio[i].checked){
checkedValue = checkedRadio[i].value;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.