Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    113
    Thanks
    6
    Thanked 1 Time in 1 Post

    Passing Iframe URL to PHP (putting Javascript var in form)

    I don't know if this is the best way to do it but I needed script to get the SRC of the iframe on my page and send it to server via Ajax...I found the below script and modified it...

    I know how to send form elements but how do I send the myFrameUrl variable? I was thinking of putting it in a hidden input but can't figure out how?...
    Code:
    <html>
    <head>
    <title>AJAX Example</title>
    <script src="prototype-1.3.1.js" type="text/javascript"></script>
    
    </head>
    <body>
    <script type="text/javascript">
    function send(){
    var params = Form.serialize($('myForm'));
    new Ajax.Updater('updateDiv', 'backend.php', {asynchronous:true, parameters:params});
    }
    
    var myFrameUrl = document.getElementById('myFrame').src;
    
    </script>
    
    <div id="updateDiv"></div>
    
    <iframe id="myFrame" src="http://google.com/" height="200px" width="200px"></iframe>
    
    <form id="myForm">
    <input name="myFrameUrl" type="hidden"><br>
    <input name="sendbutton" type="button" value="Send" onClick="send();">
    </form>
    
    </body>
    </html>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    var myFrameUrl = document.getElementById('myFrame').src;
    var params = Form.serialize($('myForm')) + '&url=' + escape(myFrameUrl);
    new Ajax.Updater('updateDiv', 'backend.php', {asynchronous:true, parameters:params});
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •