Update iframe src based on input value

I am trying to make an iframe change based on an input text field.

The line that I want to add to the URL that the user will enter is in the middle of the URL.

I tried it, but I'm not quite sure how to determine it correctly.

<script> $("#search").click(function(e) { e.preventDefault(); var url = "http://www2.sdfsdf.com/admin/agent_order_srch_ordet.asp?action=searchStrPostcode&idOrder=" $('#search').val(); "&Submit=Search"; $("#someFrame").attr("src", url; }) </script> 
+4
source share
2 answers

You have a copy error in your url variable. Here is the revised version. And I used the regular javascript version to change the url.

 <script> $("#search").click(function(e) { e.preventDefault(); var url = "http://www2.sdfsdf.com/admin/agent_order_srch_ordet.asp?action=searchStrPostcode&idOrder=" + $('#search').val() + "&Submit=Search"; $("#someFrame").get(0).src = url; }); </script> 
+2
source

Try the following:

 $("#search").click(function(e) { e.preventDefault(); var url = "http://www2.sdfsdf.com/admin/agent_order_srch_ordet.asp?action=searchStrPostcode&idOrder=" + $(this).val() + "&Submit=Search"; $("#someFrame").attr("src", url); }) 

Note that the + character is used to combine string values ​​together.

+1
source

Source: https://habr.com/ru/post/1444123/


All Articles