我知道该函数需要使用onclick或任何事件来调用。但是,如果没有用户处理,是否有可能获得隐藏的价值。
样本表格:
$ID = 3;
$Report1 = "Test1.docx";
<form id = "Test" action="Nextpage.php">
//Not sure how to call out my function over here...
<input type="hidden" id="ID" name="ID" value="<?php echo $ID ?>"/>
<input type="hidden" id="ReportPath" name="ReportPath" value="<?php echo $ReportPath ?>"/>
//Once user click, function of RemoveDoc() will handle it.
<input type="submit" id="Remove" name="<?php echo $Report1?>" value="Remove" title="Remove report1" onclick="return RemoveDoc(this.name, this.getAttribute('Report1'));" />
我的功能:
function Remove(ID, ReportPath, Report1)
{
xmlhttp1=new XMLHttpRequest();
xmlhttp1.open("GET","functions/call.php?ID="+ID+"&ReportPath="+ReportPath+"&Report1="+Report1,true);
xmlhttp1.onreadystatechange=function()
{
if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
{
document.getElementById("msg").innerHTML= xmlhttp1.responseText;
}
}
xmlhttp1.send();
return false;
}
那么我如何将输入的隐藏值传递给我的函数Remove(ID,ReportPath ...),因为它现在已隐藏且未采取任何操作。好心提醒。
答案 0 :(得分:2)
你可以得到
var id = document.getElementById('ID').value;
var reportpath = document.getElementById('ReportPath').value;
var report1 = document.getElementById('Report1').value;
调用该函数:
Remove(id, reportpath, report1);
让事情变得更轻松。你可以使用jquery。只需将其包含在您的页面中:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<form id="Test" action="Nextpage.php">
<input type="hidden" id="ID" name="ID" value="<?php echo $ID ?>"/>
<input type="hidden" id="ReportPath" name="ReportPath" value="<?php echo $ReportPath ?>"/>
<input type="submit" id="remove" name="<?php echo $Report1?>" value="Remove"/>
</form>
<script>
$('#remove').click(function(){
var id = $('#ID').val();
var reportpath = $('#ReportPath').val();
var report1 = $('#Report1').val(); //check this as I dont see it in your form
//call your function from here
Remove(id, reportpath, report1);
});
//function definition here
function Remove(id, reportpath, report1)...
</script>