Pass Variables from one page to another - JAVASCRIPT// HTML
Hello Guys!
I'm still new with javascript. I need help with passing the variables from one page to another. My page has a form (HTML) and what i would like to do is that when i click on submit, the variables or text inputted in the FIRST NAME FIELD, LAST NAME FIELD and ETC would show in the second page. Pls help... i really need to know the basics. I cant seem to find the code. thanks
Well, the easiest way would be to use server-side scripting (anyway in most cases a form needs to be passed to the server for further processing) by sending the form fields via GET or POST methods. I'll provide a example using PHP:
If you're limited to client-side processing only, then 2 option you have include:
1) using cookies to store the form data
2) pass the form data as query string to another html page.
You would then need to extract the invidual parameters from the query string in the second html page.
Maybe use this as a guide to extract the parameters from the query string.
PHP Code:
<html> <head> <title>Form Processor</title> </head> <body> <script type="text/javascript"> <!-- HIDE FROM INCOMPATIBLE BROWSERS if (window != top) top.location.href=location.href document.write("<h1>Your form has been submitted!</h1><h2>You entered the following data:</h2>");
var formData = location.search; formData = formData.substring(1, formData.length);
guys, i really appreciate your help but its seems that the code you have given is way to advance. I'm not using php, just html. do you have any other examples or explanation that a newbie like me would understand?
The javascript essentially splits the sent query string into an array with each element storing a name/value pair from your form.
If you need more info on the individual functions/methods in the javascript, you should be able to find it on the w3schools website or googling the functions/methods you're not sure of.
Bookmarks