-1

I have a simple form field with two different radio select field:

<form method="get" id="searchform" action="<?php $btn_link; ?>">
  <div class="alternativ-suchefeld">
    <div class="radioboxarea">
      <input type="radio" name="buttonname" value="value_button_1" checked>
      Button 1</div>
    <div class="radioboxarea">
      <input type="radio" name="buttonname" value="value_button_2" >
      Button 2</div>
    <input type="submit" id="searchSubmit" value="Search"  />
  </div>
</form>

If I'm choosing "Button 1" and submit, the action link "$btn_link" should be "link1.php". If "Button 2" is selected, the action link should be called "link2.php".

Has someone an idea, how to realize this ? Thank you!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Filip
  • 77
  • 2
  • 11

1 Answers1

1

Do like this

Script

 $('input[name="buttonname"]').change(function() {
  var v = $(this).val();
  if (v == "value_button_1") {
    $('#searchform').attr('action', 'link1.php');
  } else if (v == "value_button_2") {
    $('#searchform').attr('action', 'link2.php');
  }
});

Working fiddle here

Nidhi
  • 1,529
  • 18
  • 28
  • You can get the element value by using its name in jquery like `$('input[name="buttonname"]')`, so common class is not mandatory. – Mayank Pandeyz Jun 06 '17 at 09:53
  • yes, why not.Your solution also works...@MayankPandeyz – Nidhi Jun 06 '17 at 09:55
  • Thank you for the quick response. I've inserted the javascript, but however the action link always goes to "link1.php", even if I've selected button 2. The script has no effect to the sending page. Could this have something to do with the GET method? – Filip Jun 06 '17 at 12:58
  • First, apply this script open your browser inspect element in developer console and look for action attribute in form tag is it changed or not ...@Filip – Nidhi Jun 07 '17 at 03:39