dpxpz37157 2012-07-12 23:40
浏览 41
已采纳

获取表单隐藏变量到函数

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.

  • 写回答

1条回答 默认 最新

  • dtiopy6088 2012-07-13 00:37
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致