1

Why isn't this script working?

$(function() {
    var isbn = $('input').val();
    $('button').click(function() {
        $("#data").html('<iframe height="500" width="1000" src="http://books.google.com/books?vid=ISBN' + isbn + '" />');
    });
});

As you can see, I'm trying to do an extremely simple ISBN lookup field for a demo web site. The script is supposed to take the value of the input and insert it into the URL. Why isn't it working?

Also, is there a better way to accomplish this end?

I realize, of course, that iframes are rubbish, but I just want to keep it simple right now.

2
  • 2
    What isn't working? If you build the URL as a separate variable and alert() it beforehand, does it show up as you expect? Are you getting an js errors from Firebug (you are using Firebug, right ;)? Commented Jun 8, 2009 at 22:10
  • What exactly is happening? Does ISBN return a value or does the url the IFrame points to not have the GET Parameters at all? Commented Jun 8, 2009 at 22:14

3 Answers 3

2

It's not clear when your code gets called, but is this line:

var isbn = $('input').val();

only called once at page-load time, whereas it should be within the click handler:

$('button').click(function() {
    var isbn = $('input').val();
    $("#data").html('<iframe height="500" width="1000" src="http://books.google.com/books?vid=ISBN' + isbn + '" />');
});
Sign up to request clarification or add additional context in comments.

1 Comment

I knew it was something obvious like that. Thanks!
0

Why not load the page you wanted to view through the ajax load technique, so fetching the html and displaying it within the element:

$(function() {
    var isbn = $('input').val();
    $('button').click(function() {
        $("#data").load('http://books.google.com/books?vid=ISBN' + isbn);
    });
});

Comments

0

the problem is not your code but its the query string you have.

please amend as follows and it should work:

var isbn = "1603038159";

        $("#data").html('<iframe height="500" width="600" src="http://books.google.com/books?as_isbn=' + isbn);

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.