Time:
Scotland: Fri, 10:46 pm
Rhode Island: Fri, 5:46 pm
Florida: Fri, 5:46 pm
New Mexico: Fri, 3:46 pm
California: Fri, 2:46 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

CLICK HERE TO GET AUCTION BAR NOW
US$10 per year - Save $100s!
The Fabulously Unfair
WebX Auction Bar. For Ebay etc.
Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!


More information and sign-up.

WebXpertz Hosting.
Custom fit from $5pm. PHP/MySQL
You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!


Please click here for more information

For continued disscussion on this topic : Parameters using Post


jalarie
11-13-2003, 04:40 PM
I have a web form which links to another page and would like to pick up the values using JavaScript on that second page. I know how to do that if the form uses "method='get'" but I'd like to do it with the 'post' method if possible. How do I catch the incoming items using JavaScript? Thank you.

diades
11-13-2003, 05:33 PM
Hi jalarie

To my knowledge, Get is the only method that will achieve the desired result.

piglet
11-13-2003, 06:32 PM
Yes - if you want to pass things without it showing on the address line you'll have to use a cookie.

Owl
11-16-2003, 07:40 PM
Hi guys,

It can be done.
You can pass data from page to page without showing
on the location bar. Form with post method, no cookies
no frames.

There is one neglected property of the window object
which is persistent and transparent.
No matter what page (url) you link/replace/reload/refresh
in the window, as long as you don't close the window,
its name stays the same.

Since window.name is a string, we can populate it with
the form data. further more, we can format it any way
we want and make it easy for us to retrieve the data.

Here is a sample page with a post method form:<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function gatherData(f){
for(i=0; i<f.length; i++)
if(f[i].type == 'text')
name+=f[i].name+"='"+f[i].value+"';"
}
</script>
</HEAD>
<BODY>
<FORM method="post" action="actionPage.html" onsubmit="gatherData(this)">
<INPUT name="text1" value="text1Value"><BR>
<INPUT name="text2" value="text2Value"><BR>
<INPUT type="submit" value="Submit">
</FORM>
</BODY>
</HTML>

To retrieve the data in actionPage.html is as easy as: eval(name)

That's it.
All form text elements are now global variables on actionPage,
each with its own original name as identifier (try: alert(text1)).

In this case, gatherData(f) is simple because the form is simple
(text inputs only), but with little effort you can make it collect data
from any type of form element.
Actually, you can make it collect any data, not just form elements.

( •) (• )
>>V<<

piglet
11-16-2003, 09:18 PM
Hi,

That'll work in the newer browsers - just beware - Netscape 4 is very choosy about the characters it'll allow in the window name...trying to put an "=" in the name will cause the script to fail.

Still - it's another option if you're not being N4 complient... :)

KH@
11-16-2003, 09:35 PM
Piglet, I guess you are afraid of the half bee.

Netscape 4 is almost as dead as Netscape6+

I vote wise Owl !

Anyway...

to avoid an an argument

Use serverside script such as PERL PHP ASP ColdFusion to grab the POST form query string parameters and set them as JS variables. Forms submitted with method="POST" will be processed serverside.

I can give the CF code I would use below, and maybe the PHP PERL ASP dudes can add their own scripts too, even though its not pure javascript as required by this section of the forums. Seems like a good cross language thread.



say this is passed from a FORM with POST
<input type="hidden" name="example" value="foo27">


then use CF serverside to set the JS var
<cfoutput>
<cfif isdefined('example')>
<cfset example='#FORM.example#'>
<script>
/*- Think about it! is it text or numbers : quotes or not? */
var example = '#example#';
</script>
<cfelse>
<script>
var example = 'none';
</script>
</cfif>
</cfoutput>

<BODY>
<!--- then use it as you like --->
<script>
IF (example !='none') {
document.write(example);
)
</script>

</BODY>

or somthing like that. I didn't check it lol :rolleyes: The CF is OK though i think. :)

I use this type of thing frequently and it works quite well i find. It is quick and easy. Honestly, i don't think it is always best to do everything in one language unless you are doing it that way for fun or for some exam or whatever.

lorddog
11-17-2003, 03:59 PM
wise old owl,

that is awesome! why have you been hoarding this method?

simple awesome - you learn something new everyday.

Lorddog

jalarie
11-18-2003, 04:04 PM
Thank you all for your help.

Owl, that's a great idea to use window.name. I've seen it before, but had forgotten. Thanks for reminding me.

Piglet, thanks for the added warning about Netscape 4. Because of the multiple different browsers used to access our web pages, including a decent percentage of WebTV believe it or not, I normally build pages for Netscape 4, add some cute things only supported by newer browsers, and test them in everything available.

I have it working using the 'get' method and a bit of playing around. Some of the information in the link has to be secure, but not to the point of being paronoid about it, so I encoded it in Base64. It's crude, but it works.

Thanks again.

piglet
11-18-2003, 05:07 PM
Hi folks,

I am in the middle of adding this method to the FAQs.

Overnight-production-support-callout permitting I should be uploading the revised version tonight.

While doing testing I've found that you cannot use the POST method when the page is uploaded to a web-server. It works when you're testing locally using file:// - but as when tested on IIS or Apache it gave a 405 Error.

I'll post a link to the new FAQs when it's there.

Netscape 4 is almost as dead as Netscape6+

Unfortunately, N4 is very much alive. N6+ is still alive and kicking IE.....:cool:

fredmv
11-18-2003, 07:56 PM
Originally posted by piglet
but as when tested on IIS or Apache it gave a 405 Error.
I did some tests myself as well, I also got a 405 Method Not Allowed error. However, I managed to get it to work correctly. Before, I was using an HTML file as the action for the form, in that HTML file was a simple script that printed out the current value of window.name, but as we already know, when uploaded to a server a 405 Method Not Allowed error occurs. What I did was change the extension of the HTML file to .php, and interestingly enough, it worked.

It can be seen in action here: http://www.fredvaughn.org/demo/post/.

Willy Duitt
11-18-2003, 08:12 PM
Fred;

Thanks for the tip regarding using the PHP extension.
I also tried it with the .html extension and recieved
the 405 error which was noted above.

It now works for me. :tup:

.....Willy

piglet
11-18-2003, 08:18 PM
Hi,

Here's the new item in the FAQs (http://www.webxpertz.net/faqs/jsfaq/passvars.php#byname) - I've also added a section on passing things through the cookie.

When testing the FAQ I spotted a few things...

name+=blah - if you go "back" and then forward then name gets bigger and bigger - with the same info.

I've added a name="" at the start to clear it down.

If you don't qualify name as window.name, then when you run the script locally from a hard drive in Mozilla/Firebird it works - but as soon as you run it from the web-server it fails to set the attribute....hey ho. It works when you use window.name.

diades
11-18-2003, 08:28 PM
Hi Piglet

The result on the example is:
IE6 : 0 (nada:eek: )
Moz: 1

piglet
11-18-2003, 08:34 PM
Hi Keith,

Ok - now try right-click the link and "open in a new window" and try it again!

diades
11-18-2003, 08:42 PM
that works, you just have to sort accordingly now:D

piglet
11-18-2003, 08:47 PM
Ok sorted: "accdgilnory"

Stranger and strangerly....I've set up another link with target= set - that works in ie, while the popup widow one still fails. Same page...

see it now... (http://www.webxpertz.net/faqs/jsfaq/passvars.php#byname)

Maybe it's something to do with the window being named when popped up?