0

Is there a way to use a function similar to a html forms 'get' function to append a url based on the text of a textbox when a button is pressed without using a form?

    <form method="get" action="https://www.google.co.uk/">
    <input type="text" name="q"/>
    <input type="submit" value="Search">
    </form>

I don't think I can use a normal form for this because I want to have 1 textbox but two functions and two buttons (Google Search and Bing Search). If I am wrong please feel free to tell me how to add two functions to one form!

JBithell
  • 627
  • 2
  • 11
  • 27
  • possible duplicate of [add or update query string parameter](http://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter) – Cjmarkham Mar 14 '14 at 19:34
  • Way too advanced for me! I am looking for something really simple! – JBithell Mar 14 '14 at 19:38

2 Answers2

1

You could use regular buttons instead of submit buttons, and wire them to change the form's action before submitting:

<form method="get" action="https://www.google.co.uk/">
  <input type="text" name="q"/>
  <input type="button" value="Google Search" onClick="this.form.action='https://www.google.co.uk'; this.form.submit();"/>
  <input type="button" value="Bing Search" onClick="this.form.action='https://www.bing.co.uk'; this.form.submit();"/>
</form>
Nuri Hodges
  • 868
  • 6
  • 13
0

Something Like this might get you in the right direction?

<!DOCTYPE html>
<html>

<body>
    <h1>Hello Plunker!</h1>
  <input type="text" value="Value of First Text Box" id="box1">
  <input type="text" value="Value of Second Text Box" id="box2">

  <script>
  (function() {
  var x  = document.getElementById('box1').value;
  var y  = document.getElementById('box2').value;


  alert(document.location +'?'+ x + '?' + y);
  })();
  </script>

</body>

</html>

http://plnkr.co/edit/ZEso7gtHyCW241O0E59w?p=preview

But you should Ideally look at the answer posted in question comment.

defau1t
  • 10,593
  • 2
  • 35
  • 47