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

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.

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.