Passing data from forms from one page to another

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Passing data from forms from one page to another

 
0
  #1
Feb 11th, 2005
Hello,

Does anyone know how to submit forms from one page to another page? If you don' mind can someone explain how, or if they know a good tutorial, either of these would be great. Can this be done in javascript?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 764
Reputation: DaveSW is on a distinguished road 
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: Passing data from forms from one page to another

 
0
  #2
Feb 14th, 2005
I believe it's either done using cookies, or by passing (small quantities) of data in the url.

E.g. I use php to pass data on one of my sites: you create an image id number, e.g. 0000001. You link using www.mysite.com/pic.php?imgid=0000001

The second page then reads the variable imgid as having a value of 0000001. It makes a page in my templated style with 0000001.jpg in the middle, 0000001.txt included below it.

This means my one page produces up to a million image preview pages, all in my template.

If you can't get any help with it let me know and I'll see what I can suggest.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 62
Reputation: 2ndPlatform is an unknown quantity at this point 
Solved Threads: 0
2ndPlatform's Avatar
2ndPlatform 2ndPlatform is offline Offline
Junior Poster in Training

Re: Passing data from forms from one page to another

 
0
  #3
Feb 14th, 2005
Originally Posted by Dark_Omen
Hello,

Does anyone know how to submit forms from one page to another page? If you don' mind can someone explain how, or if they know a good tutorial, either of these would be great. Can this be done in javascript?

Thanks
You can do it a variety of ways -- one being what DaveSW suggested. In PHP, at least, you don't need to pass it as a URL variable.

Forms using the POST method (which is... well.... yeah, duh)... can send variables to the next page, you just have to write the code to grab them. Easy enough to do. What language do you want to use?

What are you trying to accomplish -- do you have some starter code I can look at? I'd be glad to help.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Passing data from forms from one page to another

 
0
  #4
Feb 15th, 2005
Well I found an example from another page, but I want to do it in javascript, and here is the code that I got.
This is the form I am working with:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form name="input" action="">
  2. Username:
  3. <input type="text" name="user">
  4. <input type="submit" value="Submit">
  5. </form>

I don't know what action to use or if there is any other part that I need for javascript, and I don't know the code for the recieving end page.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Passing data from forms from one page to another

 
0
  #5
Feb 15th, 2005
the said javascript that cooresponds to the submit button, takes on the form: document.formname.submit();
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Passing data from forms from one page to another

 
0
  #6
Feb 17th, 2005
does that go in value
so:

value="document.formname.submit()"

or

does it go in action like this:
action="document.formname.submit()"

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Passing data from forms from one page to another

 
0
  #7
Feb 17th, 2005
I would have put it in a function... but you can put it as an action if you want....such as
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <input type="button" value="hi" onClick="document.formname.submit();" />

or in a function.. because I like to test the form values with javascript BEFORE submitting it to the server-side.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function check_values()
  2. {
  3. if (document.formname.sometextbox.value == "") {
  4. alert("How About A Value in sometextbox buddy!?")
  5. return;
  6. } else {
  7. document.formname.submit();
  8. }
  9. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Passing data from forms from one page to another

 
0
  #8
Feb 18th, 2005
I am not using a server, how do u submit using a cookie
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 1
Reputation: jinijavalearner is an unknown quantity at this point 
Solved Threads: 0
jinijavalearner jinijavalearner is offline Offline
Newbie Poster

Re: Passing data from forms from one page to another

 
0
  #9
Mar 11th, 2005
Hi,
I hope its not too late to ask another related question on this. I am also trying to the same thing, passing data from one page to another, using javascript and html. From the replies in this post, I can send data from my input page. But after that I have to display all the sent data (username, address, location etc.) in the new page. How do I do that?
thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 355
Reputation: DanceInstructor is an unknown quantity at this point 
Solved Threads: 14
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: Passing data from forms from one page to another

 
0
  #10
Mar 11th, 2005
These are the fuctions you need. I suggest you make a file called cookie.js and include in your html file like this:

[HTML]<script type="text/javascript" src="cookie.js"></script>[/HTML]

and the javascript to place in the cookie.js file:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //
  2. // Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
  3. //
  4. // Written by: Bill Dortch, hIdaho Design <bdortch@hidaho.com>
  5. // The following functions are released to the public domain.
  6. //
  7. // This version takes a more aggressive approach to deleting
  8. // cookies. Previous versions set the expiration date to one
  9. // millisecond prior to the current time; however, this method
  10. // did not work in Netscape 2.02 (though it does in earlier and
  11. // later versions), resulting in "zombie" cookies that would not
  12. // die. DeleteCookie now sets the expiration date to the earliest
  13. // usable date (one second into 1970), and sets the cookie's value
  14. // to null for good measure.
  15. //
  16. // Also, this version adds optional path and domain parameters to
  17. // the DeleteCookie function. If you specify a path and/or domain
  18. // when creating (setting) a cookie**, you must specify the same
  19. // path/domain when deleting it, or deletion will not occur.
  20. //
  21. // The FixCookieDate function must now be called explicitly to
  22. // correct for the 2.x Mac date bug. This function should be
  23. // called *once* after a Date object is created and before it
  24. // is passed (as an expiration date) to SetCookie. Because the
  25. // Mac date bug affects all dates, not just those passed to
  26. // SetCookie, you might want to make it a habit to call
  27. // FixCookieDate any time you create a new Date object:
  28. //
  29. // var theDate = new Date();
  30. // FixCookieDate (theDate);
  31. //
  32. // Calling FixCookieDate has no effect on platforms other than
  33. // the Mac, so there is no need to determine the user's platform
  34. // prior to calling it.
  35. //
  36. // This version also incorporates several minor coding improvements.
  37. //
  38. // **Note that it is possible to set multiple cookies with the same
  39. // name but different (nested) paths. For example:
  40. //
  41. // SetCookie ("color","red",null,"/outer");
  42. // SetCookie ("color","blue",null,"/outer/inner");
  43. //
  44. // However, GetCookie cannot distinguish between these and will return
  45. // the first cookie that matches a given name. It is therefore
  46. // recommended that you *not* use the same name for cookies with
  47. // different paths. (Bear in mind that there is *always* a path
  48. // associated with a cookie; if you don't explicitly specify one,
  49. // the path of the setting document is used.)
  50. //
  51. // Revision History:
  52. //
  53. // "Toss Your Cookies" Version (22-Mar-96)
  54. // - Added FixCookieDate() function to correct for Mac date bug
  55. //
  56. // "Second Helping" Version (21-Jan-96)
  57. // - Added path, domain and secure parameters to SetCookie
  58. // - Replaced home-rolled encode/decode functions with Netscape's
  59. // new (then) escape and unescape functions
  60. //
  61. // "Free Cookies" Version (December 95)
  62. //
  63. //
  64. // For information on the significance of cookie parameters,
  65. // and on cookies in general, please refer to the official cookie
  66. // spec, at:
  67. //
  68. // http://www.netscape.com/newsref/std/cookie_spec.html
  69. //
  70. //******************************************************************
  71. //
  72. // "Internal" function to return the decoded value of a cookie
  73. //
  74. function getCookieVal (offset) {
  75. var endstr = document.cookie.indexOf (";", offset);
  76. if (endstr == -1) {
  77. endstr = document.cookie.length;
  78. }
  79. return unescape(document.cookie.substring(offset, endstr));
  80. }
  81.  
  82. //
  83. // Function to correct for 2.x Mac date bug. Call this function to
  84. // fix a date object prior to passing it to SetCookie.
  85. // IMPORTANT: This function should only be called *once* for
  86. // any given date object! See example at the end of this document.
  87. //
  88. function FixCookieDate (date) {
  89. var base = new Date(0);
  90. var skew = base.getTime(); // dawn of (Unix) time - should be 0
  91. if (skew > 0) { // Except on the Mac - ahead of its time
  92. date.setTime (date.getTime() - skew);
  93. }
  94. }
  95.  
  96. //
  97. // Function to return the value of the cookie specified by "name".
  98. // name - String object containing the cookie name.
  99. // returns - String object containing the cookie value, or null if
  100. // the cookie does not exist.
  101. //
  102. function GetCookie (name) {
  103. var arg = name + "=";
  104. var alen = arg.length;
  105. var clen = document.cookie.length;
  106. var i = 0;
  107. while (i < clen) {
  108. var j = i + alen;
  109. if (document.cookie.substring(i, j) == arg) {
  110. return getCookieVal (j);
  111. }
  112. i = document.cookie.indexOf(" ", i) + 1;
  113. if (i == 0) {
  114. break;
  115. }
  116. }
  117. return null;
  118. }
  119.  
  120. //
  121. // Function to create or update a cookie.
  122. // name - String object containing the cookie name.
  123. // value - String object containing the cookie value. May contain
  124. // any valid string characters.
  125. // [expires] - Date object containing the expiration data of the cookie. If
  126. // omitted or null, expires the cookie at the end of the current session.
  127. // [path] - String object indicating the path for which the cookie is valid.
  128. // If omitted or null, uses the path of the calling document.
  129. // [domain] - String object indicating the domain for which the cookie is
  130. // valid. If omitted or null, uses the domain of the calling document.
  131. // [secure] - Boolean (true/false) value indicating whether cookie transmission
  132. // requires a secure channel (HTTPS).
  133. //
  134. // The first two parameters are required. The others, if supplied, must
  135. // be passed in the order listed above. To omit an unused optional field,
  136. // use null as a place holder. For example, to call SetCookie using name,
  137. // value and path, you would code:
  138. //
  139. // SetCookie ("myCookieName", "myCookieValue", null, "/");
  140. //
  141. // Note that trailing omitted parameters do not require a placeholder.
  142. //
  143. // To set a secure cookie for path "/myPath", that expires after the
  144. // current session, you might code:
  145. //
  146. // SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
  147. //
  148. function SetCookie (name,value,expires,path,domain,secure) {
  149. document.cookie = name + "=" + escape (value) +
  150. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  151. ((path) ? "; path=" + path : "") +
  152. ((domain) ? "; domain=" + domain : "") +
  153. ((secure) ? "; secure" : "");
  154. }
  155.  
  156. // Function to delete a cookie. (Sets expiration date to start of epoch)
  157. // name - String object containing the cookie name
  158. // path - String object containing the path of the cookie to delete. This MUST
  159. // be the same as the path used to create the cookie, or null/omitted if
  160. // no path was specified when creating the cookie.
  161. // domain - String object containing the domain of the cookie to delete. This MUST
  162. // be the same as the domain used to create the cookie, or null/omitted if
  163. // no domain was specified when creating the cookie.
  164. //
  165. function DeleteCookie (name,path,domain) {
  166. if (GetCookie(name)) {
  167. document.cookie = name + "=" +
  168. ((path) ? "; path=" + path : "") +
  169. ((domain) ? "; domain=" + domain : "") +
  170. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  171. }
  172. }

This code has served me well

Dance
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC