简体   繁体   中英

How to pass php variable value to div's iframe using href

 <?php $query="SELECT * FROM `notification` where `Status`='1' && `ownerid`='$userid' "; $result = mysql_query($query); $count=0; while($row=mysql_fetch_array($result)) { $nid=$row['notifid']; $pr="select * from `Swap` where `notifid`='$nid'"; $prm=mysql_query($pr); $prow=mysql_fetch_assoc($prm); $rid=$prow['Requesterid']; $query1="select * from `myuser` where `Userid`='$rid'"; //echo $query1; $result1=mysql_query($query1); $row1=mysql_fetch_assoc($result1); $rname=$row1['Firstname']; //echo $rname; ?> <div style="width:100%; background: rgb(228, 228, 228);margin: 20px;padding: 20px;"> <h1>A New Swapping Request from <?php echo $rname; ?></h1> Your sweater is choose for swapping.....you want to give permission?? <div onclick="clicked(this);" id="<?php echo $nid; ?>">VIEW REQUEST</div> </div> <?php $count++; } ?> <div id="light" class="white_content" style=" height: auto;"> <a href = "javascript:void(0)" style="background: #EAEAEA; padding: 5px 7px; color: #000; float: right;" onclick="confirmno()">X</a> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript"> function clicked(item) { document.getElementById('light').style.display='block'; document.getElementById('fade').style.display='block'; var a = $(item).attr("id"); } </script> <div id="stylized" class="myform"> <iframe width="100%" height="400px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="confirmed.php?x="+a> </iframe> </div> </div> 

hi, here i want to pass unique php variable via href/anything else into for i frame src to pass.after see numbers of tutorials i get the value of $nid in $(item).attr("id"); but how to pass this value to i try u can see in my code..but its not working plz help

If js is in separate file (.js), then it's not parsed by PHP and therefore PHP tags won't work there.

In this case You could solve this by 2 scenarios:

1) Move function declaration to file that is parsed by PHP (like second block of Your code, where this function is called)

2) Add input parameter to "confirmno" function. Parameter sets "nid" value and it is given by PHP file (instead of 'onclick="confirmno()' You would use 'onclick="confirmno()'.

Code:

<script type="text/javascript">
    function confirmno(nid) {
    var con=confirm('You want keep this?');
    if (con == true) {
      window.location="notification.php";
    } else {
      window.location="confirmed1.php?nid=" + nid;
    }
}
</script>

<a href = "javascript:void(0)" style="background: #EAEAEA; padding: 5px 7px; color: #000; float: right;" onclick="confirmno(<?php echo $nid; ?>)">X</a>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM