Greetings!
I have here code that sends values via ajax. That values includes an array.
<script type = 'text/javascript'>
function insert() {
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else {
xmlhtttp = new ActiveXObject('Microsoft.XMLHttp');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState ==4 && xmlhttp.status == 200) {
document.getElementById('message').innerHTML = xmlhttp.responseText;
}
}
parameters = 'keyword='+document.getElementById('keyword').value + '&accnum='+document.getElementsByName('accnum[]').value;
/*"parameter1=" + parameter1.value + "¶meter2=" + parameter2.value*/
xmlhttp.open('POST', 'Borrow_2.php', true);
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send(parameters);
}
</script>
<script type = 'text/javascript'>
function addRow()
{
tabBody=document.getElementById("inputtable");
row=document.createElement("TR");
cell1 = document.createElement("TD");
textnode1=document.createElement("input");
textnode1.name="accnum[]";
textnode1.type="text";
cell1.appendChild(textnode1);
row.appendChild(cell1);
tabBody.appendChild(row);
}
</script>
</HEAD>
<BODY>
<form id="test" onsubmit="return false;" autocomplete="off">
<div class="main">
<table>
<tbody id="inputtable">
<div id="holder">
<p>Student ID: <input type="text" id="keyword" tabindex="0" name = 'keyword'></p>
<div id="ajax_response"></div>
<tr><td>SAccession No: <input type="text" id="accnum" tabindex="0" name = 'accnum[]' >
<input type="button" value="Add new" onclick="addRow();" /></td></tr>
<br/>
<br/>
<br/>
<input type="submit" value="submit" onClick="insert();"/>
My problem is I can’t get the value of my accnum.
I think the problem is this line, and I don’t know how to fix it.
parameters = 'keyword='+document.getElementById('keyword').value + '&accnum='+document.getElementsByName('accnum[]').value;
When I used var_dump(); it says that ‘undefined strings’. What’s that mean? thank you.