Google Answers Logo
View Question
 
Q: forms and prompts in HTML/Javascript ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: forms and prompts in HTML/Javascript
Category: Computers > Programming
Asked by: fieldlily-ga
List Price: $10.00
Posted: 27 Nov 2005 10:34 PST
Expires: 27 Dec 2005 10:34 PST
Question ID: 598159
I am trying to make a website that does the following: when a visitor
enters text into a form and hits Submit, the website displays that
text further down the page (not in a form field; as part of the body
text). Is there a way to do this without knowing CGI? For example, can
you set up the webpage so that, when the visitor enters text and
submits it, that entry gets assigned a JavaScript variable and can be
read/used later in the page?

As this question probably shows, I am a JavaScript novice, but I am
willing to put in some effort if I can get this done w/o CGI/other
backend programming. Thanks everybody.

Request for Question Clarification by palitoy-ga on 27 Nov 2005 10:50 PST
Hello fieldlily-ga

Before submitting an answer for you can you clarify whether the page
can be refreshed (that is the form is posted) when the user hits
"Submit"?

palitoy-ga

Clarification of Question by fieldlily-ga on 27 Nov 2005 13:43 PST
Yes, the page can be refreshed. (It would be a little cooler if it
wasn't necessary, but not a big deal at all.) Thanks. ~fieldlily-ga

Clarification of Question by fieldlily-ga on 27 Nov 2005 14:03 PST
Come to think of it, it would also work if the text the visitor
entered could be displayed in a new form field farther down the page.
If you are able to tell me how to do both of these things (have the
visitor's input display as part of the body text, and also have the
visitor's input display in a new form farther down the page), I will
double the price of the question to $20. Thank you.
Answer  
Subject: Re: forms and prompts in HTML/Javascript
Answered By: palitoy-ga on 28 Nov 2005 03:11 PST
Rated:5 out of 5 stars
 
Hello fieldlily-ga

Thank-you for your question.

The solution b_cummins-ga has provided us with a good basis to start
on but unfortunately does not work in Firefox (or Mozilla based)
browsers.  As these now are used by approximately 10% of the people
surfing the internet we should make the script compatible.  Luckily
this is simple to do.

The problem with b_cummins-ga's script is the use of innerText which
is only fully supported by Internet Explorer.  To make it compatible
simply change innerText to innerHTML.

This makes the example below read:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Change on submit</title>
</head>
<body>
<p>First box:<br />
<input type="text" name="first"><input type="button" value="Submit"
onClick="document.all.second.value = document.all.first.value;
document.all.inpara.innerHTML = document.all.first.value">
</p>
<p>Second box:<br />
<input type="text" name="second">
</p>
<p>You typed:<br /><div id="inpara">nothing</div></p>
</body>
</html>

Should you require any further assistance on this matter please do not
hesitate to ask for clarification.
fieldlily-ga rated this answer:5 out of 5 stars and gave an additional tip of: $15.00
Worked like a charm. Thanks very much for an easy and effective solution.

Comments  
Subject: Re: forms and prompts in HTML/Javascript
From: b_cummins-ga on 27 Nov 2005 15:19 PST
 
try this.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>

</head>

<body>
First box:<br>
<input type="text" name="firstBox"><input type="button" value="go"
onClick="document.all.secondBox.value = document.all.firstBox.value;
document.all.theBody.innerText = document.all.firstBox.value">
<br><br><br>
Second box, further down the page:<br>
<input type="text" name="secondBox">
<br><br><br>
and in the body the word is <b><div id="theBody">not set</div></b>
</body>
</html>
Subject: Re: forms and prompts in HTML/Javascript
From: palitoy-ga on 28 Nov 2005 10:55 PST
 
Thank-you for the 5-star rating and generous tip!  They are both appreciated.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy