Document reprinted by the Fire Site Building Institute (bkjia.com)Sometimes we have to change the form action to submit data. Of course, in most cases, we use hidden fields to make actions get different data. For example, the form action is search. php, so we all hide the field so that we can use search. php searches for different values, such as <input type = "hidden" name = "action" value = "article"> and. in php, $ _ POST ['action'] = 'Article' is used to know that the content we search for is an article rather than other content.
But what if we do not have only one entry to search. php? For example, our full-text search is search. php, the search article is search_article.php, And the search news is search_news.php. What should I do? Of course, you can change the FORM action through the value in the drop-down box.
The simple code is as follows:
Reference content is as follows:
- <Script type = "text/javascript">
- <! --
- Function redirectForm (which ){
- Var searchModeList = document. getElementById ('searchmode ');
- Var actionFile = '';
- For (var I = 0, sml = searchModeList. length; I <sml; I ++ ){
- If (I = searchModeList. selectedIndex ){
- ActionFile = searchModeList [I]. value;
- }
- }
- If (actionFile = ''){
- Return false;
- } Else {
- ActionFileactionFile = actionFile + '. php ';
- }
- Which. action = actionFile;
- Which. submit ();
- }
- // -->
- </Script>
- <Form method = "post" action = "" onsubmit = "return redirectForm (this);" id = 'searchform'>
- <Select id = "searchMode">
- <Option value = "search" selected = "selected"> Default </option>
- <Option value = "search_article"> Article </option>
- <Option value = "search_news"> News </option>
- </Select>
- <Input type = "submit"/>
- </Form>
|
Article from: http://www.neatcn.com/show-411-1.shtml