简体   繁体   中英

How to get the input box value from form to iframe?

<html>
  <script type="text/javascript">  
    function showIFrame() {  
      var iframe = document.getElementById("output");  
      iframe.style.display="block";  
    }  
  </script>
  <form method="get"  name="search" id="search"  target="carsearch">
    <b>Enter Text</b><input type="text" id="pv2" name="pv2"/>
    <input type="submit" value="Report Generation" class="submitBtn" id="SearchCarButton" onclick="showIFrame()"/>

    <iframe id="output" style="border:1px solid;width:1000px;height:500px;" src="/00ON0000000FOHS?pv2=" name="carsearch">
    </iframe>
  </form>

</html>

I need to take that input value and to keep it in the iframe Src="/00ON0000000FOHS?pv2=(value)" ? How can i do that?

it has to take the value and get loaded

Try this

<html>
<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">  
 function showIFrame()
{
 var url='/00ON0000000FOHS?pv2=('+$('#pv2').val()+')';
  $('#output').show();
 $('#output').attr('src', url);
}
</script>
    <form method="get"  name="search" id="search"  target="carsearch">
        <b>Enter Text</b><input type="text" id="pv2" name="pv2"/>
        <input type="submit" value="Report Generation" class="submitBtn" id="SearchCarButton" onclick="showIFrame()"/>

     <iframe id="output" style="display:none;border:1px solid;width:1000px;height:500px;" src="/00ON0000000FOHS?pv2=" name="carsearch">
</iframe>
</form>

</html>

DEMO

Yes it should be possible, even if the site is from another domain.

$('input:button[name=save]').click(function() {
        var name = $('iframe[name=select_frame]').contents().find('#select_name').val();
    });

I will suggest you to add data-src attribute, to iframe

JavaScript

function showIFrame() {
    var myIframe = $('#output');
    myIframe.attr('src', myIframe.attr('data-src') + $('#pv2').val());
    myIframe.show();
}

HTML:

<iframe id="output" src="" data-src="/00ON0000000FOHS?pv2=" name="carsearch" style="display:none;border:1px solid;width:1000px;height:500px;" >
</iframe>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM