Web Analytics Made Easy -
StatCounter Setting a src of iframe with form submit - CodingForum

Announcement

Collapse
No announcement yet.

Setting a src of iframe with form submit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Setting a src of iframe with form submit

    Hi, i am trying to set the src of a iframe on submitting a form.
    Here is the code :

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function changeSrc()
    {
    alert("Hello");
    document.getElementById("myframe").src="http://google.com";
    }
    </script>
    </head>
    <body>
    <form onsubmit="changeSrc()" target="myframe">
     <!--<input type="button" onclick="changeSrc()" value="Change Source" />  -->
    <input type="submit"  value="Change Source" />
    </form>
    <iframe id="myframe" name="myframe">
    <p>Your browser does not support iframes.</p>
    </iframe>
    <br /><br />
    </body>
    </html>
    The js function is being called but the src attribute is not set and an other iframe is created within the iframe. I want to set the src only on form submit. How do i fix this? Thanks.
    Last edited by BinaryBird; Aug 31, 2011, 07:36 AM.

  • #2
    You are calling your function on submit. A normal submit will always result in refreshing the main page, if you don't actively prevent this from happening. The usual way is to return false from the onsubmit

    So try this
    Code:
    <form onsubmit="changeSrc(); return false;" rel="nofollow" target="myframe">

    Comment


    • #3
      Originally posted by devnull69 View Post
      You are calling your function on submit. A normal submit will always result in refreshing the main page, if you don't actively prevent this from happening. The usual way is to return false from the onsubmit

      So try this
      Code:
      <form onsubmit="changeSrc(); return false;" rel="nofollow" target="myframe">
      Thanks, that worked. May i know what rel="nofollow" for?

      Comment


      • #4
        rel="nofollow" does not make any sense on a form tag. It is specified for <a> anchor tags only and will ask a search engine bot to not consider this link for link popularity. However not all search engine bots respect this restriction anyway.

        Comment

        Working...
        X