tags:

views:

49

answers:

3

I have a simple text box and button.

When clicked the button should change the src attribute of an iframe as follows:

src="**script.php?=**(value of text box)

I have managed to get the iframe to work when simply changing the src to be only the contents of the text box using this code:

$(document).ready(function() {

// Change iFrame on a Button Click Event
    $("#myButton").click(function(event){
        $("#myIFrame").attr('src', $('#url').val());
    });
});

How can i add the "script.php?=" before the $('#url').val()

Thanks!!!!

+1  A: 
$(document).ready(function() {

// Change iFrame on a Button Click Event
    $("#myButton").click(function(event){
        $("#myIFrame").attr('src', 'script.php?=' + $('#url').val());
    });
});
Ryan Ternier
+1  A: 

Just concatenate it:

$(document).ready(function() {
    var prefix = 'script.php?=';
    // Change iFrame on a Button Click Event
    $("#myButton").click(function(event){
        $("#myIFrame").attr('src', prefix + $('#url').val());
    });
});
jmar777
Awesome!! Thanks!!
OB85
Sure thing :) As an aside, there seems to be a missing query string parameter name... e.g., script.php?<some-param>=<some-value> (this was hinted at by @Tomasz's suggestion).
jmar777
A: 

Am I not thinking correctly, or you just need the:

$("#myIFrame").attr('src', 'script.php?param=' + $('#url').val());
Tomasz Kowalczyk