4

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

The string that I want to append to the url that the user will input is in the middle of the url though.

Have tried but not quite sure how to define 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>

2 Answers 2

2

You have a copy paste error inside your url variable. Here's the corrected version. And I used the plain 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>
Sign up to request clarification or add additional context in comments.

2 Comments

Hi thanks for this I have tried it but it does not update the iframe. I can see it adding src in firebug but it is empty.
Hi there it was my fault. Had wrong id's that stopped it working. Its fine now. Many thanks
1

Try this:

$("#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 the + character is used to concatenate string values together.

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.