0

I have the html structure like this

<form id="form_search">
    <input type="text" id="url_iframe"/>
    <button id="search">Start</button>
</form>
<iframe id="iframe_search" >
</iframe>

and I trying to set the iframe scr from javascript like this

window.onload = function ()
{
   document.getElementById('search').onclick = inicializar;

   function inicializar ()
   {
     var url_iframe = "http://localhost/site/index.php";
     document.getElementById('iframe_search').src = url_iframe;            
   }
}

But the problem is that the iframe not retain the scr value...

How can I set property to iframe?

Thanks!

2 Answers 2

1

You need to prevent the default event behavior on your mouse click event. A better option would be to add the event to the submit event to support older browsers.

http://jsfiddle.net/xd2d9/1/

event.preventDefault();
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you should move your inicializar() function outside the window.onload() function because I guess you will need a function with a global scope to run it onclick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.