0

drop down select "sales" go to sales.php, other options selected go to addFund.php...

<form name='searform' method='post' action='<?php echo $home;?>addFund.php'>
Search : <input type='text' id='sear' name='sear'> by 
<select id='psel' name='psel' onchange='change()'>
<option value='email'>Email</option>
<option value='name'>Username</option>
<option value='domain'>Domain name</option>
<option value='sales'>Sales</option>
</select>
<input type='submit' name='sub' id='sub' value='Go' onclick='gopage()'>
<input type='submit' name='dir' id='dir' value='Direct'>
</form>

How to submit different pages

3 Answers 3

2

You could use some Javascript nastiness to achieve this with the change() function, but the usual way to do this is to route all requests through a controller and include() the appropriate page. For example, point your form to action.php, and in that file, do this:

action.php

<?php

  if (isset($_POST['psel']) && $_POST['psel'] == 'sales') {
    include 'sales.php';
  } else {
    include 'addFund.php';
  }

...or you could just put roughly that code into addFund.php, since you only seem to have one other script that you would want to send requests to.

Sign up to request clarification or add additional context in comments.

Comments

1

You could do this with javascript:

function change(el) {
  if(el.value === 'sales') {
    el.form.action = 'sales.php';
  } else {
    el.form.action = 'addFund.php';
  }
}

Change the onchange to onchange="change(this)". A better way would be to check the variable on serverside and include the right file.

4 Comments

how to call this change() function? "go" button onclick event or onsubmit()?
You would put this in the onchange= attribute of the <select> (as it does clearly say above)
@jey you have already a onchange='change()' in your select. Just add this to change and it should work. This calls the change() method when you select an entry. You may need to add my code to an existing function...
@binarious: i put in code.. its works.. The search code used all pages "header.php".but single issue.. i select "sales" go to sales.php. then email is selected default option.so submit go to addFund.php. but again go to sales.php.
-1

Change your select to this:

<select name="vote" onChange="document.forms['searForm'].submit()">

And make your form action go to something like pageChange.php where it returns a different page depending on the $_POST value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.