简体   繁体   中英

Update a parent div using javascript

So I have several modal windows on my site. I usually use jquery and ajax to accomplish something in the modal window and to update a div on the parent page.

My problem here is I'm uploading files so I'm forced to use an iframe which I never do and Im using javascript, not jquery which I never do, so I'm a little lost and looking for some direction.

I'm trying to update a div on the parent page from my modal window. In the modal window I have a form which targets an iframe and the action is directed at a separate php page. The overall question is how do I send an updated $attachment_table to a parent div after the form has uploaded its files? I'm trying:

Modal_window.php - has a form on it that uploads files.

<?php
$attachment_table = '';
while (($row73 = $answer17->fetch(PDO::FETCH_ASSOC)) !== false) {
                          $attachment_table .= '<tr>';
                          $attachment_table .= "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='${row73[imageven_id]}'></td>";
                          $attachment_table .= "<td><a href='../php/viewimages.php?id=${row73[image_id]}')'>${row73[upload_name]}</a></td>";
                          $attachment_table .= "<td>${row73[image_category]}</td>";
                          $attachment_table .= "<td>${row73[upload_date]}</td>";
                          $attachment_table .= '</tr>';
                      };

?>    

<script type="text/javascript">

        function stopUpload(success) {
            var result = '';
            if (success == 1) {
                window.top.document.getElementById('attachment_table').innerHTML = <?php echo $attachment_table; ?>;
                document.getElementById('result').innerHTML = '<div class="msg-status" style="width:492px;">The file was uploaded successfully!<\/div><br/>';
            } else if (success == 0) {
                document.getElementById('result').innerHTML = '<div class="msg-error" style="width:492px;">There was an error during file upload!<\/div><br/>';
            } else if (success == 2) {
                document.getElementById('result').innerHTML = '<div class="msg-error" style="width:492px;">ERROR! Please upload a document with the following file types....<br/><br/>txt, doc, xls, rtf, ppt, pdf, jpg, jpeg, gif, png, xlsx, docx, png, pps, ppsx, ppt<\/div><br/>';
            }
            document.getElementById('f1_upload_process').style.visibility = 'hidden';
            return true;
        }
    </script>

modal_window_process.php - Processes database code and sends response which is $result

<script language="javascript" type="text/javascript"> 
window.top.window.stopUpload(<?php echo $result;?>);
</script>

Can someone point me in the right direction please? I couldn't find anything on the web on how to do this and I'm a self taught noob. Thx.

If the iframe parent has this function

<script type='text/javascript'>
    function onUploaderReady() {
        alert('upload ready');
    }
</script>

You can have the modal_window_process.php script call the onUploaderReady function by returning a response like this

<html>
<head>
    <script type='text/javascript'>
        parent.onUploaderReady();
    </script>
</head>
</html>

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