I know that function will need to call out by using onclick or any events. But is it possible to get a hidden value without user handling.
Sample Form:
$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'));" />
My function:
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;
}
So how can i pass in the hidden value of the input into my function Remove(ID,ReportPath...) since it's now hidden and no action taken. Kindly advise.
You can just get
var id = document.getElementById('ID').value;
var reportpath = document.getElementById('ReportPath').value;
var report1 = document.getElementById('Report1').value;
Call the function:
Remove(id, reportpath, report1);
To make things easier for you. You can use jquery. Just include it in your page:
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.