Solved

Sending Input Variable in Action Tag

Posted on 2003-12-03
8
458 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now