Zool Posted October 17, 2011 Share Posted October 17, 2011 Hi, In a parent/iframe page, I would like to update the parent URL on a change in the iframe. Here is a description of my problem: I have a booking page with an iframe. The iframe has a calendar script for selecting an available date; this date is passed to the parent page to complete the booking. I get the iframe url from the parent page with the script below which works fine: src="iframe.php?id_item=<?php echo $_REQUEST["id_item"] ?>" I however would like to have the parent URL update when a user changes the item_id in the iframe. Is there a way to pass the “item_id” value to the parent to update the URL? I have a select box in the iframe which is used to change the item_id: <select name="id_item" class="select" onchange="this.form.submit();"> '.sel_list_items($_REQUEST["id_item"]).' </select> Is there a way to add a script to the onchange command to send the item_id to the parent URL? Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/ Share on other sites More sharing options...
requinix Posted October 17, 2011 Share Posted October 17, 2011 You can use parent to access the parent window. Which means you can also call its functions... Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280000 Share on other sites More sharing options...
Zool Posted October 17, 2011 Author Share Posted October 17, 2011 I tried the code below, but it doesn't seem to work. parent.document.getElementById('id_item').value = 'id_item'; What am I getting wrong? Just to add to the record, I am learning PHP as I build my site, so have a very basic knowledge. I appreciate any help/advise given. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280020 Share on other sites More sharing options...
requinix Posted October 17, 2011 Share Posted October 17, 2011 I don't know. It's hard to tell without being able to see any code. Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280028 Share on other sites More sharing options...
Zool Posted October 17, 2011 Author Share Posted October 17, 2011 HI, The parent page has the a iframe and a form. a snippet of the code is: <div id="mainContent"> <div id="frameedge" align="center" > <iframe id="frame" width="650" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="iframe.php?id_item=<?php echo $_REQUEST["id_item"] ?>">Calendar</iframe> </div> <div id='BookingForm_errorloc' class='error_strings' style=''></div> <form action="formsubmit.php" method="POST" name="BookingForm" id="BookingForm" url="formsubmit.php" width="600" height="1500" > <!-- form inputs start here --> the iframe code is: <body> <?php $idno = $_REQUEST["id_item"]; echo ' <form action="" method="get" name="Calendar" > <div class="clear"></div> <h2>'.itemTitle(ID_ITEM).'</h2> <div id="cal_wrapper" align="center"> <div id="cal_controls" > <!-- calendar month change buttons --> <div id="cal_prev" title="Previous"><img src="images/icon_prev.gif"></div> <!-- class="cal_button"--> <div id="cal_next" title="Next"><img src="images/icon_next.gif"></div> <div id="cal_admin"><!-- calendar change item select box --> <select name="id_item" class="select" onchange="this.form.submit();"> '.sel_list_items($_REQUEST["id_item"]).' </select> </div> <!-- end options --> </div> <div id="the_months" align="center"> <!-- Draw calendar --> '.$calendar_months.' </div> <div id="key_wrapper"> <!-- Draw calendar key --> '.$calendar_states.' </div> <div class="clear"></div> </div> </form> '; ?> </body> What I would like to do is to add a function to the onchange of the iframe to update the item_id in the parent page. Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280035 Share on other sites More sharing options...
requinix Posted October 17, 2011 Share Posted October 17, 2011 id_item is in the iframe, not the parent document... Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280067 Share on other sites More sharing options...
Zool Posted October 18, 2011 Author Share Posted October 18, 2011 Hi, i use the id_item in the url to select the item to show the calendar for. the iframe picks up the id_item from the parents url "/test.php?id_item=3". there is a form in the parent page which the user books the item, so i need to know the id_item to book the correct item (even if it is passed to a variable $id). the problem is that if the user changes the id_item in the iframe, i cannot get this value back to the parent page. Thank you for your help on this - very much appreciated! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280126 Share on other sites More sharing options...
requinix Posted October 18, 2011 Share Posted October 18, 2011 You can't because you're referencing things that don't exist in the parent. parent.document.getElementById('id_item').value = 'id_item'; There is no id_item in the parent document. Only in the iframe's document. Quote Link to comment https://forums.phpfreaks.com/topic/249250-parent-url-from-iframe/#findComment-1280304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.