我有一张这样的表:
CheckBox Course Semester Paper Level
[] ABC 1 1 •Expert •normal
[] ABC 1 2 •Expert •normal
[] ABC 1 3 •Expert •normal
[Save]
在上表中,复选框值为纸张值。我遇到的麻烦是,当我点击保存时,它会运行一个参数化的javascript函数addpapers($ course,$ semester),因为你可以看到它们是相同的,但我无法将复选框值和级别值一起发送。一个人可以为给定的纸张选择专家级别或正常级别。我无法用javascript发送它们。
function flagaddpapers(course, semester) {
displayBox = document.getElementById("studentBox");
elements = document.getElementsByName('pids[]');
levelid = document.getElementsByName('radios[]');
data = [];
for (i = 0; i < elements.length; i++) {
if (elements[i].checked) {
data.push('pids[]=' + encodeURIComponent(elements[i].value));
}
}
params = "teacher=" + encodeURIComponent(teacher) + "&course=" + encodeURIComponent(course) + "&semester=" + encodeURIComponent(semester) + "&flag=" + encodeURIComponent(1) + "&" + data.join('&');
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.body.removeChild(document.getElementById('loadMsg'));
result = xmlhttp.responseText;
alert(result);
displayBox.className = "dimBox";
setTimeout(function () {
ajaxstp();
document.body.removeChild(document.getElementById('adBackground'));
document.body.removeChild(document.getElementById('adBox'));
}, 200);
}
}
xmlhttp.open("POST", "tpaper.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(params);
}
这是我的HTML代码:
echo "<tr>
<th style='font-size:12px;'><input type='checkbox' id='master_check'
onclick='masterSelect();' style='display:inline-block;cursor:pointer;'></th>
<th style='font-size:12px;'>S.No</th>
<th style='font-size:12px;'>Course</th>
<th style='font-size:12px;'>Semester</th>
<th style='font-size:12px;'>Level</th>
<th style='font-size:12px;'>Paper</th></tr>";
$counter17 = 1;
while($row4 = mysql_fetch_array($q4))
{
$pids = $row4['pid'];
echo "<tr>";
echo "<td><input type='checkbox' name='pids[]' class='persistentChecks'
style='display:inline-block;cursor:pointer;' value=".$pids."></td>";
echo "<td style='text-align:center;font-size:12px;'>".$counter17."</td>";
echo "<td style='text-align:center;font-size:12px;'>".$row4['cname']."</td>";
echo "<td style='text-align:center;font-size:12px;'>".$semester."</td>";
echo "<td style='font-size:12px;'><input type='radio' name='radio[]' id='radio1'
value='1'>Expert</input><input id='radio2' type='radio' name='radio[]'
value='2'>Normal</input></td>";
echo "<td style='text-align:center;font-size:12px;'>".$row4['pname']."</td></tr>";
$counter17 = $counter17 + 1;
}
echo "</table>";
echo "<div style='text-align:left;'><input type='button' class='t_s' value='Add Paper'
onclick='flagaddpapers(".$course.",".$semester."); return false'
id='addpaperBtn'><input type='button' class='t_s' value='Cancel' onclick='closedialog();
return false'></div>";
答案 0 :(得分:0)
试试这个..
这里pval
是paperid
而lval
是level value
<script type="text/javascript">
function merge_value(lval,pval)
{
document.getElementById(pval).value=pval + '-' + lval;
}
</script>
<?php
echo "<tr>
<th style='font-size:12px;'><input type='checkbox' id='master_check'
onclick='masterSelect();' style='display:inline-block;cursor:pointer;'></th>
<th style='font-size:12px;'>S.No</th>
<th style='font-size:12px;'>Course</th>
<th style='font-size:12px;'>Semester</th>
<th style='font-size:12px;'>Level</th>
<th style='font-size:12px;'>Paper</th></tr>";
$counter17 = 1;
while($row4 = mysql_fetch_array($q4))
{
$pids = $row4['pid'];
echo "<tr>";
echo "<td><input type='checkbox' name='pids[]' id='".$pids."' class='persistentChecks'
style='display:inline-block;cursor:pointer;' value=".$pids."></td>";
echo "<td style='text-align:center;font-size:12px;'>".$counter17."</td>";
echo "<td style='text-align:center;font-size:12px;'>".$row4['cname']."</td>";
echo "<td style='text-align:center;font-size:12px;'>".$semester."</td>";
echo "<td style='font-size:12px;'><input type='radio' name='radio[]' id='radio1'
value='1' onClick='javascript:merge_value(this.value,".$pids.")'>Expert</input><input id='radio2' type='radio' name='radio[]'
value='2' onClick='javascript:merge_value(this.value,".$pids.")'>Normal</input></td>";
echo "<td style='text-align:center;font-size:12px;'>".$row4['pname']."</td></tr>";
$counter17 = $counter17 + 1;
}
echo "</table>";
echo "<div style='text-align:left;'><input type='button' class='t_s' value='Add Paper'
onclick='flagaddpapers(".$course.",".$semester."); return false'
id='addpaperBtn'><input type='button' class='t_s' value='Cancel' onclick='closedialog();
return false'></div>";
?>