php - How do I submit a form using image links to change form action with JS (no JQuery)? -


i have search form needs processed 3 different ways:

1) default action of form should submit using return/enter key.

2) if "image1" clicked $which_action variable needs updated , submit form.

3) if "image2" clicked $which_action variable needs updated , submit form.

(i know $which_action not exist in client browser, have included placeholder in following code)

here have notes on i'd do:

<form method="post" action="<?php echo $which_action ?>" id="query">      <input type="text" value="<?php echo $_post['query']; ?>" /> </form>  <image1>clicking image should change $which_action=image1.php , post form value $_post['query'] while submitting form. <image2>clicking image should change $which_action=image2.php , post form value $_post['query'] while submitting form. 

the javascript should not effect default method of submitting form enter/return key.

thank in advance!

  <form method="post" action="" id="query">  <input type="text" value="<?php echo $_post['query']; ?>" /> </form>   <img src="" onclick="changeaction('image1.php')">  <img src="" onclick="changeaction('image2.php')">   <script>    function changeaction(url) {    document.getelementbyid("query").action = url;    document.getelementbyid("query").submit();   }   </script> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -