Solved

Sending Input Variable in Action Tag

Posted on 2003-12-03
8
463 Views
Last Modified: 2010-04-09
How do I send the form input as a parameter in an action statement?  Below testSearchValue validates the input.  If all is well, that searchText variable needs to be sent to search.html.  Naturally below the text string "searchText" is being passed.  I need its value to be passed.  Thanks!

<form method="post" onsubmit="return testSearchValue(this)" action="search.html?page_number=1&user_input=searchText">
      <input name="searchText" type="text" size="30"/>
      <input type="submit" value="Go!"/>
      <input type="reset" value="Reset"/>
</form>
0
Comment
Question by:bparmelee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:mrh30
ID: 9873067
It's much more simple than you're making it!

<form method="post" action="search.html">
    <input name="searchText" type="text" size="30" />
    <input name="page_number" type="hidden" value="1" />
    <input type="submit" value="Go!" />
    <input type="reset" value="Reset" />
</form>

And believe it or not, both searchText and page_number will be submitted as CGI parameters when the form is submitted.  I don't know what language you're writing in, but in Perl you'd just be able to pull the parameters out with $q->param('searchText') and $q->param('page_number') statements.
0
 
LVL 3

Accepted Solution

by:
daveroydunn earned 500 total points
ID: 9873437
If you want the variables to appear at the end of the address you need to use the GET method.

<form method="get" onsubmit="return testSearchValue(this)" action="search.html">
     <input name="searchText" type="text" size="30"/>
     <input type="submit" value="Go!"/>
     <input type="reset" value="Reset"/>
</form>

Alternatively if you don't want the variables to appear at the end of the address you need to use the POST method.

<form method="post" onsubmit="return testSearchValue(this)" action="search.html">
     <input name="searchText" type="text" size="30"/>
     <input type="submit" value="Go!"/>
     <input type="reset" value="Reset"/>
</form>

Using the POST method means that any processing of the variables would need to be done Server Side.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9874705
But if you really want them to be on the querystring using post, you will have to change the action of the form dynamically in the testSearchValue() function.  In that function, just before you return true, change the action like this:

 function testSearchValue(theForm)
 {
    // your validation code ...

    // ... then if everything validates:
 
    var page_number = 1;  // or however you get this info
    var user_input = "searchText";
    theForm.action = "search.html?page_number=" + page_number + "&user_input=" + searchText;
    return true;
 }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:knightEknight
ID: 9874722
OOPS ... typo in the most important line!   should be:

   theForm.action = "search.html?page_number=" + page_number + "&user_input=" +  user_input;

(use the variable name at the end)
0
 
LVL 3

Expert Comment

by:mrh30
ID: 9874742
But as Daveroy has already pointed out, you can do that with GET.  There's not a lot of point in having a convoluted way of doing things when the easy way is supplied for you!
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9875034
true, but GET has limitations on how much data it can pass.  It is sometimes convenient to pass some data in the form and some on the querystring.  I do this all the time in ASP to keep the form data collection seperate from the page control data collection.  However, since that does not appear to be how it is being used here, I prefer your suggestion of using hidden fields.   But my suggestion above is another alternative, and one that addresses the question directly.
0
 
LVL 3

Expert Comment

by:mrh30
ID: 9875061
Yes, I agree with you.  A lot of the work we do involves websites passing quite a lot of CGI data around, so we almost always use POST and several hidden fields.
0
 

Author Comment

by:bparmelee
ID: 9879139
Thanks to all!  The GET worked.  I originally used the Javascript method above, but it seemed to not want to work with PHP.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 88
Table doesn't show the lines! 3 36
HTML INPUT 6 39
HTML CSS and  Table design 4 70
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question