1

I'm trying to obtain an input class=input type=text to add to a link not related to the page's address. The resulting link+text-entry will be displayed in an iframe.

I tried the following (which I found on here):

function GET_IT() {
    var link = document.getElementById("LINKHERE");
    var hrefOrig = link.href;
    var dd = document.getElementById("TEXT_ID");
    dd.onchange = function(){ link.href = hrefOrig + dd.value; }
}
window.attachEvent("load", init, false);

with:

<form target="IFRAME" method="get">
    <input class"input" type="text" size="25" id="TEXT_ID">
    <input type="submit" value "Go" onClick="javascript: function('GET_IT');">
</form>

All it did was loop back the page that everything was entered into, in the iFrame...

Stephen
  • 593
  • 3
  • 20

1 Answers1

0

Your JavaScript function should look something like this:

function GET_IT() {
    var link = document.getElementById("LINKHERE");
    var hrefOrig = link.href;
    var dd = document.getElementById("TEXT_ID");

    //Change the source of the iFrame with the new HREF...
    document.getElementById('IFRAME ID').src = hrefOrig + dd.value;
}

This is the best answer I can give you without seeing more code. Check out this link for a more complete example that might help you:

Changing iframe src with Javascript

Fiddler Example:

http://jsfiddle.net/VkSRY/1/

Community
  • 1
  • 1
LNendza
  • 1,350
  • 1
  • 12
  • 21
  • I'm not having a problem with the iframe, it's that i can't attach the entry in the text field to the end of the specified link. whenever this is attempted it just displays the original page in the iframe instead. – user2070685 Feb 25 '13 at 20:13
  • Is there a way to add it to the "action" ? like...
    – user2070685 Feb 25 '13 at 20:20
  • Are you able to debug through your javascript (With Chrome Debugger or Firebug) and see what is being returned? – LNendza Feb 25 '13 at 20:21
  • It's rough and should be rewritten to be clearer and catch any errors, but if should point you in the right direction. – LNendza Feb 25 '13 at 20:39
  • Sweet the example on fiddle.net worked great. Thanks! One question. It pops a confirmation box (white box with the link and variable together, and an OK button) anyway to prevent that and just have it do it's thing? – user2070685 Mar 08 '13 at 15:25
  • Yes, just remove the "alert(newSrc)" – LNendza Mar 08 '13 at 15:48