0

here is my code. I can not pass the edit_id to script and passback to <div class="modal fade" id="copy3" role="dialog"> please help.

the row[0] is not global, that why I can't get it in the same page. so I want to post again, to the script, and then , use $_POST or $_GET, but not working...

<PHP---here is a link>

    ......
    <td align="center">[<a class="get_copy3" href="<? echo $_SERVER["PHP_SELF"]."#?edit_id=$row[0]";?>">Copy3</a>]</td>
    ....

    <SCRIPT> (this is a popup script)

        $(".get_copy3").on("click", function(e) {
                        e.preventDefault();             
                        var $edit_id = $(this).data('edit_id');
                        document.cookie = $edit_id ;
                        $('#copy3').modal('show');
                    });
        .....
   <SCRIPT>



<php and html--------here is a popup>    
    <div class="modal fade" id="copy3" role="dialog"> 
    <? echo $edit_id; ?>
    </div>
Angeloli
  • 1
  • 1
  • Anyway in this scenario, it would make a lot more sense to use Javascript to populate the contents of your modal. There is no need to send the data to the server (so that PHP can execute it) and back again. – ADyson May 07 '20 at 09:04
  • 1
    You could just write `$('#copy3').html($edit_id);` to replace the contents of the modal with your ID. – ADyson May 07 '20 at 09:05
  • my code , the edit_id is null. nothing. – Angeloli May 07 '20 at 10:11
  • Well that's probably because `$(this).data('edit_id')` returned null. And that in turn is probably because whatever thing you clicked on doesn't have a data-attribute called `edit_id`. You asked how to pass the edit_id to the modal, so I showed you. If you didn't create an edit_id value in the first place, then that's a separate problem you need to resolve. Looking at the ` – ADyson May 07 '20 at 10:20

1 Answers1

1

You can do like this :

$(".get_copy3").on("click", function(e) {
                    e.preventDefault();             
                    var edit_id = $(this).data('edit_id');
                    document.cookie = edit_id ;
                    $("#edit_input").val(edit_id);
                    $('#copy3').modal('show');
                });

 <div class="modal fade" id="copy3" role="dialog"> 
       <input type="hidden" id="edit_input" /> 
    </div>


if you want to pass back then you click event and set input of hidden in parent body to the value.

Avinash Dalvi
  • 8,551
  • 7
  • 27
  • 53