www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: how to pass value to iframe src attribute

  1. #1
    Join Date
    May 2010
    Posts
    11

    how to pass value to iframe src attribute

    I just stucked somewhere in js, i know its simple task but i don't know what's wrong but i believe i just need little guidance to get my result.
    Here is my problem

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>sample</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/javascript">
    function OfferTwo(){
    var Name = document.getElementById("txtName").value;
    var Email = document.getElementById("txtEmail").value;
    var sUrl = document.getElementById('offer2').src;
    document.getElementById('offer2').src = 'http://www.getmyname.com?info.php?dp=0&l=0&p=0&Name='+Name+'&email='+Email;
    alert(document.getElementById('offer2').src);
    }
    </script>
    </head>
    
    <body>
    <form name="myFrom" method="get" action="">
      <p>Name 
        <input name="txtName" type="text" id="txtName">
      </p>
      <p>Email 
        <input name="txtEmail" type="text" id="txtEmail">
      </p>
      <p>Yes 
        <input type="radio" name="rb" value="radiobutton" onClick="OfferTwo();">
        No
        <input type="radio" name="rb" value="radiobutton">
      </p>
    </form>
    <iframe name="offer2" id="offer2" src="" height="500px" width="100%" frameborder="0" scrolling="no">Your Browser not supporting</iframe>
    </body>
    </html>
    what i am trying to do on radio click 'YES' option i pass the value into querystring. Till now i got sucess to pass values but now problem is that how i pass this value into iframe src element.

    I tried alot did lot of googling but didn't get anything yet.

    Please help me, i know its very basic thing but i didn't trace my mistake.

    Thanks i n advance

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    offer2.location = 'http://www.getmyname.com ...

  3. #3
    Join Date
    May 2010
    Posts
    11
    thanks for reply but its not working, same behaviour.
    I did this in my JS fucntion

    Code:
    <script language="JavaScript" type="text/javascript">
    function OfferTwo(){
    var Name = document.getElementById("txtName").value;
    var Email = document.getElementById("txtEmail").value;
    var sUrl = document.getElementById('offer2').src;
    document.getElementById('offer2').location = 'http://www.getmyname.com?info.php?dp=0&l=0&p=0&Name='+Name+'&email='+Email;
    alert(document.getElementById('offer2').location);
    }
    </script>

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    A reference to the iframe name
    Code:
    offer2.location

  5. #5
    Join Date
    May 2010
    Posts
    11
    Yes, the reference to iframe is offer2 but where i do this i mean as far as i know it has been in JS function.
    May be i am wrong, can you please ammend in my code and post here i am really gratefull to you.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <script language="JavaScript" type="text/javascript">
    function OfferTwo(){
    var Name = document.getElementById("txtName").value;
    var Email = document.getElementById("txtEmail").value;
    offer2.location = 'http://www.getmyname.com?info.php?dp=0&l=0&p=0&Name='+Name+'&email='+Email;
    alert(document.getElementById('offer2').location); // only gives the correct value once the page loads
    }
    </script>

  7. #7
    Join Date
    May 2010
    Posts
    11
    oh thank you so much this is really great help, you are CHAMP

  8. #8
    Join Date
    May 2010
    Posts
    11
    Code:
    <script language="JavaScript" type="text/javascript">
    function OfferTwo(){
    var Name = document.getElementById("txtName").value;
    var Email = document.getElementById("txtEmail").value;
    offer2.location = 'http://www.getmyname.com?info.php?dp=0&l=0&p=0&Name='+Name+'&email='+Email;
    alert(document.getElementById('offer2').location); // only gives the correct value once the page loads
    
    innerIframe_OF2.location =document.landingForm.submit(); // want to auto sumbit }
    </script>
    i want to auto sumbit the information but javascript showing error
    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
    Timestamp: Tue, 1 Jun 2010 23:55:39 UTC


    Code:
    Message: 'document.landingForm' is null or not an object
    Line: 35
    Char: 1
    Code: 0
    URI: http://getmyname.com/
    any guidance is appreciable

  9. #9
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    innerIframe_OF2.document.landingForm.submit()

  10. #10
    Join Date
    May 2010
    Posts
    11
    Thank you so much, can you tell me their is anyway to post data cross the domain.
    Actually my all the above efforts to sumbit my form data to 3rd party direct submission without click any sumbit button.

  11. #11
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    By adding the form query to the url. In 99&#37; of cases this will fail due to form method and security restrictions.

  12. #12
    Join Date
    May 2010
    Posts
    11
    yeah, you rite but their is anyway or any technique we can perform this task like to get form element on our page and then populated those fields and submit on third part URL.

    I think i go for website or web page scrapping or try YQL or something like this. What you say ? any suggestions or guidance is appreciable.

  13. #13
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Server side validation will normally prevent hacking.

  14. #14
    Join Date
    May 2010
    Posts
    11
    You mean their is no way we can perform this task?

  15. #15
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Whether you can or can not will depend on the site. Most sites will block such a request.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles