2

This form is search form. when I click the <option> "alfamart" or "bca", I want the link change. like this, link: /en2/maps(alfamart)or(bca)/ in accordance with the <option>
but how?

thanks

<form action="/en2/maps".$id."/"><!--Relative url to the page that your map is on-->

    Distination: 
    <select name="textSearchTerms" class="selectpicker" data-live-search="true">
        <option value="alfamart">Alfamart</option>
     <option value="BCA">BCA</option>
    </select> 
    <input type="submit" value="Search">
</form>

<?php
$id = $_GET['textSearchTerms'];
?>
Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47
Abed Putra
  • 1,153
  • 2
  • 17
  • 37
  • 1
    i dont see why you wanna do it because PHP will send the selected data anyway on the server and you can process with that.? – pritesh Feb 08 '16 at 07:13
  • You should do this with JQuery, possible you need this: http://stackoverflow.com/questions/5451600/jquery-to-change-form-action – Pedram Feb 08 '16 at 07:14
  • Do you want to change the place where the action will be done i.e. the `action` attribute or you want to redirect the user who submitted the form to url that has the search term in it? – Ognjen Babic Feb 08 '16 at 07:14
  • @jiff—yes, it's possible with any one of a dozen libraries. I'm sure the OP is aware of that. – RobG Feb 08 '16 at 07:22
  • Why not a listener on the select's change event? Then `this.form` gets the form, and `this.form.action` the *action* property to munge as you wish using `this.value` to get the value of the selected option. But why not just send the value of the select as form data and let the server work it out? – RobG Feb 08 '16 at 07:23

1 Answers1

0

You don't need to get value from URL, you can change form action by select box value.

$('.selectpicker').change(function(){
if($(this).val() == 'alfamart'){
 $('form').attr('action','alfamart.html');
  alert('action is alfamart.html');
} else {
 $('form').attr('action','BCA.html');
  alert('action is BCA.html');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="/en2/maps">

    Distination: 
    <select name="textSearchTerms" class="selectpicker" data-live-search="true">
        <option value="alfamart">Alfamart</option>
       <option value="BCA">BCA</option>
    </select> 
    <input type="submit" value="Search">
</form>
Pedram
  • 15,766
  • 10
  • 44
  • 73