Forum Moderators: open
For instance: Let's say I wanted to have the search form on WEB to search Google (I can set up the form) but how do I make it so the action changes when you click on IMAGES (let's say I wanted it to search Google Images - again, I can set up the form for that, but how do I make it so the action changes when clicking the tab?)
Thanks! :)
[edited by: eelixduppy at 2:41 am (utc) on Mar. 15, 2009]
[edit reason] removed URL [/edit]
function updateAction(q,f){
var form = document.getElementById(f);
form.action = q;
}
the your form would look like this,
<form method='post' action='search.php' name='search' id='form'>
Query: <input type='text' name='q' /> <input type='submit' value='search..' />
<br />
<a href='#' onClick="updateAction('imagesearch.php','form');">Image Search</a>
and you could list as many actions as you wanted, just editing the action with updateAction, only you cant append form actions with a REQUEST so you would need diffrent pages for each search type, which i think is messy, so a better way would to add a hidden value called searchtype that just updates on click and then use a php to search depending on what came in on 'searchtype'...
function updateValue(v,i){
var field = document.getElementById(i);
field.value = v;
}
your HTML would then look like this,
<form method='post' action='search.php' name='search' id='form'>
Query: <input type='text' name='q' /> <input type='submit' value='search..' />
<input type='hidden' name='searchtype' id='searchtype' value='search' />
<br />
<a href='#' onClick="updateValue('image','searchtype');">Image Search</a>
hope that makes sense, the best way i think is the second...
[edited by: Kings_on_steeds at 1:12 pm (utc) on Mar. 15, 2009]