Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using form inputs with java script

Status
Not open for further replies.

bkj123

Technical User
Aug 23, 2002
43
US
Hello. I have a web page with a form that asks the user for their name and few other inputs. I'd like to send the inputs to another webpage that creates a letter.

A simplified example is a form that asks for the:
- user's name (<uname>),
- their govenor's name (<gname>)
- and a question they want to ask their govenor (<ques>).

They hit enter and they go to another page where they see a letter formatted like:

Dear <gname>:

My Name is <uname>. Please answer the question below. Thank you.

<ques>

can the form processing be done using javascript? Thanks you.
 
The action page you declare in your form tag will have refrences to to the input element values. You need to look into some server side script like Coldfusion or pearl...

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Yes, a server side language is most suited and this isn't a javascript issue. However, here is a quick/rough/simple example of how you could do it in perl (which would be similar in e.g. PHP):

HTML Webpage (index.htm)
Code:
<form action="script.pl" method="post">
<p>Username: <input type="text" name="username"></input></p>
<p>Governer's Name: <input type="text" name="governorname"></input></p>
<p>Question To Ask The Governer: <input type="text" name="question"></input></p>
</form>

Perl Script (script.pl)
Code:
#! /usr/bin/perl
use strict;
use CGI ':standard';
print "Content-type: text/html\n\n";

my $username = param('username');
my $governername = param('governername');
my $question = param('question');

print qq(
<p>Dear $governername:</p>

<p>My Name is $username.  Please answer the question below.  Thank you.</p>

<p>$question</p>
);

For further help, you should direct your questions to another forum such as the perl, php, coldfusion etc etc forum.

Chris
 
Hmm, obviously a submit button would help :p

Code:
<input type="submit" name="submit" value="Submit"></input>

Chris
 
Actually you can deliver your form data to another page purely with client-side JS but the question is what will you do with that data on next page...

However, exploiting HTTP get method you can pass form values to URL and then reat them on other page

--first page--
<code>
<form action="another_page.html" method="get">
<input name="uname"><input name="gname"><input name="ques">
<input type="submit" value="send"></form>
</code>

After submitting form the address bar will look like

so you have to process url to get values you need:

--second page--
<code>

q=location.search.replace('?','').split('&');
frm={}
for(i in q){
frm[q.split('=')[0]]=q.split('=')[1];
}

document.open();
document.write(frm.uname);
document.write('<br>');
document.write(frm.gname);
document.write('<br>');
document.write(frm.ques);
document.close();

</code>

Avar Pentel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top