0

For the following HTML

<form>
    Enter hash here: <input type="text" name="hash">
       <button type="submit" formaction="/tasks/">Retrieve Url</button>
</form>

How can I re-direct the user to /tasks/A where A = whatever the user typed in the "hash" <input> box?

Thanks

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384

3 Answers3

1

Take a look at this post will help.

It do exactly the same thing you want with example.

Community
  • 1
  • 1
Bowie
  • 992
  • 3
  • 10
  • 25
0

You'd need to either prevent the submit's default action (event.preventDefault();), or change the button from type="submit" to type="button", then use JavaScript to set the form's action. Here's some jQuery that could do the job for you:

$('button').click(function() {
    //set the form action
    $('form').attr('action', '/tasks/'+$('input[type="text"]').val())
    //submit the form
    .submit();
});

See a working example at http://jsfiddle.net/jhfrench/BQ8MW/

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
-1

You could use a temporary post and redirect. For example:

<?php
if(isset($_POST['hash'])){
header("Location:/tasks/" . $_POST['hash']);
}
?>

Or if you want you could use AJAX to collect the value and then redirecting without the refresh.

Devon Bernard
  • 2,250
  • 5
  • 19
  • 32