user3191137
user3191137

Reputation: 135

jquery: Appending url extension to existing iFrame url

I'm trying to change my iframe on button click by appending nfl/ to http://espn.go.com/. Unfortunately, nothing happens when the button is clicked. I would make a jsfiddle but everytime I save the fiddle, it just goes to espn.com on pageload

<iframe src="http://espn.go.com/" id="GMapsframe" height="300px" width="600px"></iframe>

<button id="button1" onclick="GMapTest(nfl/);">TEST</button>

jquery:

function GMapTest(facilityID) {
         var url = 'http://espn.go.com/';
         $('#GMapsframe').attr('src', url + facilityID);
         return false;
                    }

EDIT: Added return to onclick="return GMapTest('nfl/');" however now is just goes to the new website instead of inserting it into the iframe.

Upvotes: 0

Views: 69

Answers (2)

user3191137
user3191137

Reputation: 135

Added name='GMapTest' to html, added return and passed the name in the parameters within the onclick.

<button id="button1" onclick="return GMapTest('GMapsframe','nfl/');">TEST</button>

Upvotes: 0

Amit Joki
Amit Joki

Reputation: 59262

Call it like this:

GMapTest('nfl/');

The facilityID is a string.

<button id="button1" onclick="GMapTest('nfl/');">TEST</button>

Upvotes: 1

Related Questions