1

This seems simple enough but nothing I try has been working, it's getting pretty frustrating.

Here is the Javascript:

function vf(loc) {
    var x = document.getElementById('frame').src;
    var n = x.indexOf("?f");
    var f = x.substring(n, n + 2);
    var nn = x.indexOf("?t");
    var t = x.substring(nn, nn + 1);
    var f = loc;
    var link = "/Home/VidList?f=" + f + "?t=" + t;
    document.getElementById('frame').src = link;
}

And the HTML:

<a href='#' onclick="vf('MP')">Most Popular</a>
<iframe id="frame" src="/Home/VidList/"></iframe>

It works fine if I change it to:

document.getElementById('frame').src = "test";

Or anything else, and it works and shows the correct link of the text if I do something like:

document.getElementById('test').innerHtml = link;

But for some reason settin the .src to that variable does not work. Simply nothing happens and the src is not changed at all.

Thank you in advance for your time.

EDIT:

Upon further investigation it looks like the "?" character is the offender, removing that from the string allows it to work fine, how can I get it to allow the question mark?

user2463732
  • 29
  • 2
  • 10
  • 2
    did you mean to write `var link = "/Home/VidList?f=" + f + "&t=" + t;` - it is important to delimit your query string with & and not ?. – attila May 05 '14 at 22:19
  • What are you trying to do? You are looking for strings in the URL that aren't there, which causes you to use -1 in the `substring` calls. Do you get any error messages? – Guffa May 05 '14 at 22:21
  • Yes, & is correct but it does not change the issue. – user2463732 May 05 '14 at 22:37
  • You can use this answer http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – keypaul May 05 '14 at 22:49

0 Answers0