Example Tutorial: Use JS to change the FORM action

Source: Internet
Author: User

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:
  1. <Script type = "text/javascript">
  2. <! --
  3. Function redirectForm (which ){
  4. Var searchModeList = document. getElementById ('searchmode ');
  5. Var actionFile = '';
  6. For (var I = 0, sml = searchModeList. length; I <sml; I ++ ){
  7. If (I = searchModeList. selectedIndex ){
  8. ActionFile = searchModeList [I]. value;
  9. }
  10. }
  11. If (actionFile = ''){
  12. Return false;
  13. } Else {
  14. ActionFileactionFile = actionFile + '. php ';
  15. }
  16. Which. action = actionFile;
  17. Which. submit ();
  18. }
  19. // -->
  20. </Script>
  21. <Form method = "post" action = "" onsubmit = "return redirectForm (this);" id = 'searchform'>
  22. <Select id = "searchMode">
  23. <Option value = "search" selected = "selected"> Default </option>
  24. <Option value = "search_article"> Article </option>
  25. <Option value = "search_news"> News </option>
  26. </Select>
  27. <Input type = "submit"/>
  28. </Form>

Article from: http://www.neatcn.com/show-411-1.shtml

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.