0

hi,

Hours i've spent looking and the answer still eludes me.

I am trying to create a dynamic hyperlink, based on the current page url and information appended from a text entry box ideally using PHP / javascript / iframe.

I do not want to reload the page to get the form data into the hyperlink.

For example

Original page url
http://thispage.com/cars/

Text entry field

[ text entered here ]

Submit

Resulting dynamic hyperlink, which i will display as an image.

http://thispage.com/cars/[ text entered here ]

Surely it can't be that hard?

Drink for a solution.

thanks

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by diafol
0

Something like this:

function(input, link) {
  input.onkeyup = function() {
    link.href = 'http://thispage.com/cars/' + input.value;
  };
}(document.getElementById('input_id'), document.getElementById('link_id'));

Oops, didn't read your post carefully. Changed it slightly.

Edited by twiss: n/a

0

JS solution easiest, but could be a problem for those with limited js or js turned off.

You could use a redirect:

if(isset($_POST['mypage'] && $_POST['mypage'] !="")){
  header("Location: " . $_SERVER['PHP_SELF'] . "/" . $_POST['mypage']);
}

You need to place this right at the top of the page before any html output or whitespace.

You could go further like checking the page exists first with file_exists(). You could even have a select box with a dropdown of available pages to reduce the chance of a 404 error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.