title: How to set src in iframe using Javascript
body: <p>I'm working on a MVC project right now and the current feature being developed is a DropDownList with each option tied to a URL. When the user selects an item and presses Submit, the expected behaviour is for the page to load an iframe on the same page with the particular URL tied to their selection displayed in said frame.</p>
  
  <p>Controller:</p>
  
  <pre><code>Function Configuration() As ActionResult
  
          Dim configList As List(Of String) = New List(Of String)
          configList.Add("10GBaseLX4")
          configList.Add("10GFC")
          configList.Add("10GigE")
          configList.Add("100BaseFX")
  
          ViewData("cprotocols") = New SelectList(configList)
          Return View()
  
      End Function
  
      Public Function Handle(ByVal cprotocols As String) As String
          Return "http://www.configlist.com/" + cprotocols + "_Config.xml"
      End Function
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;% Using (Ajax.BeginForm("Handle", New AjaxOptions With {.OnComplete = "showConfig"}))%&gt;
      Select a configuration file to view: &lt;%= Html.DropDownList("cprotocols") %&gt;
          &lt;br /&gt;
  
          &lt;input type="submit" value="Submit" /&gt;
          &lt;br /&gt;
          &lt;%End using %&gt;
          &lt;br /&gt;
          &lt;script type="text/javascript"&gt;
          function showConfig(cprotocols)
          {
              var param1 = cprotocols;
              document.write('&lt;iframe src="' + param1 + '"&gt;&lt;/iframe&gt;');
          }
          &lt;/script&gt;
      &lt;/p&gt;
  </code></pre>
  
  <p>That's what i have in the view right now, but what ends up happening is that:</p>
  
  <ol>
  <li><p>The frame appears AFTER I press submit; ideally, I'd like the frame to already exist on the page, then have the url requested load inside it after submit is clicked. Is this possible?</p></li>
  <li><p>A new page pops up, the frame is there, but I get a 404 "resource does not exist" error (obviously from the javascript syntax being wrong). My goal is to have the file requested load on the same screen as the DDL.</p></li>
  <li><p>The URL is dealt with entirely by the Handle() action.</p></li>
  </ol>