Publish a form using AJAX

Do you have an idea how to send the name of my radio button to

myAjaxPostrequest.send(parameters);

may be such parameters:

var answername=document.getElementById('option1').name;

var parameters=answername;

? this code is for using ajax to submit the form

and my php page needs the name of the click that the radio camera clicks on

I tried this code and it works the way I want, except to insert into the database. This means that the parameters are problems.

what I want to insert is the number located between the brakes of the name of the radio object.

I could do this when I submit the form without AJAX, but now I cannot submit the name of the radio

Any clue on what I can send as a parameter to a function 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>
+3
source share
2

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);
+1

:

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;
   }
}
0

Source: https://habr.com/ru/post/1749069/


All Articles