...

View Full Version : display form results in a textbox



barracuda11201
12-04-2002, 07:09 PM
hello --

im new to javascript ....

anyway, im creating a form .... checkboxes, radio buttons, textboxes etc ....

onSubmit - i created a new window that displays the information that was selected from the form ....

the new window displays everything i selected just fine.

currently all information that displays on the new window is just text that cant be changed or updated.

how can i change this so that the results show in a "textbox" (instead of plain text) so the user could say change the information or something???

im not using any cgi or php to submit the results or anything ....

beetle
12-04-2002, 08:04 PM
You have a form with multiple controls (text inpute, checkboxes, etc) and you would like to show the results in a SINGLE textarea? Do I get you right?

Or do you want only the data they entered to re-appear in a similar form control on the new page, so that it can be edited and re-submitted (confirmed)?

barracuda11201
12-04-2002, 08:41 PM
"Or do you want only the data they entered to re-appear in a similar form control on the new page, so that it can be edited and re-submitted (confirmed)?"


yes this is what i want ....... :)

beetle
12-04-2002, 08:50 PM
Oooh. I'd seriously consider giving the user a confirm message instead first.

<form ... onsubmit="return confirm('Are you sure the data you entered is accurate and complete?');" ... >

What you ask for CAN be done, but is no simple task, and could take several hours to accomplish. Sorry, I just don't do that kind of work unless I'm supremely interested in the result or I'm being paid, and I'm not THAT intersted in the result :D

barracuda11201
12-04-2002, 08:58 PM
ok let me simplify what im looking to do ......

lets take a form with one textbox where the user enters a quanity.......

at this present time i can show the results of the quanity on a new window that opens up but it is displayed in a plain text form that can not be manipulated ......

id like to have that one textbox quanity display on that new window in a textbox (instead of plain text) so the user can change the quanity ....

can anyone help me?

beetle
12-04-2002, 09:06 PM
Sure. I'm assuming you are using GET method forms and for this example, assume that your quantity field is named "quantity"

in the popup page

<html>
<head>
<title>Whatever</title>
<script type="text/javascript">
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split("&");
var nameVal, val;
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split("=");
val = (typeof nameVal[1] == 'undefined') ? '' : unescape(nameVal[1]);
getVars[unescape(nameVal[0])] = val;
}
return getVars;
}
var _GET = parseGetVars();

function setFormValues(f) {
f.qty.value = _GET['quantity'];
}

</script>
</head>

<body>
<form method="GET" onload="setFormValues(this);">
<input type="text" name="qty" />
</form>
</body>
</html>

whammy
12-05-2002, 01:02 AM
I have a strange sense of dejavu... ;)

(Which usually means if you had searched the forums, you may have found the answer yourself. ;)).

There's even a tutorial for this here:

http://www.javascriptkit.com/javatutors/send1.shtml

although I think that beetle's solution (and mine) are much easier to implement (and very similar)... i.e.:



<script type="text/javascript">
<!--
function QueryString(str){
var q = window.location.search;
var foundValue = ""
if(q.length > 1){
this.q = q.substring(1, q.length);
}
this.keyValuePairs = new Array();
if(q){
for(var i = 0; i < this.q.split("&").length; i++){
this.keyValuePairs[i] = this.q.split("&")[i];
if(this.keyValuePairs[i].split("=")[0] == str){
foundValue = unescape(this.keyValuePairs[i].split("=")[1]);
}
}
}
return foundValue;
}
//-->
</script>

:D

barracuda11201
12-05-2002, 04:27 AM
well i do thank the 2 people that took the time to offer help ...

id like to add that i started out with the words "im new to javascript" ..... which means im learning, and im trying real hard ...

however, the 2 posters kinda came off snooty and made me feel like a idiot .....

before i posted on here i searched this site for well over an hour ... im new, so maybe i didnt know where to search etc......

anyway, im frustrated cause i still cant get the code working :(

glenngv
12-05-2002, 05:37 AM
I'm wondering why you would display again the form in a new window then let the user edit the inputs in that new window.
You can just ask the user the confirmation if the entered data in the main window are correct. So beetle's original solution would suffice:
<form ... onsubmit="return confirm('Are you sure the data you entered is accurate and complete?');" ... >
...
<input type="submit" value="Submit">
</form>

No need for the new window. The user can change the data he entered by choosing the Cancel button in the confirm box.

barracuda11201
12-05-2002, 05:49 AM
thanks glen ...

i do need a confimation window..... trust me lol

i simply want to know how to display the results - such as a quantity of an item - in a new confirmation window but in a textbox instead of just plain text .....

the site is spread out .....so i DO need to have a new window like this ... tough to explain i guess - but it only makes sense for the user

thanks cindy :)

glenngv
12-05-2002, 07:25 AM
ok, can you show some of your code that displays just plain text?

whammy
12-06-2002, 12:48 AM
First of all, I want to apologize for myself AND beetle, if you read our comments as "snooty", I know mine were intended to help, and I'm sure beetle's were too. :)

I'm not totally sure about beetle's script since I haven't messed around with it, but with mine you'd want the code I posted to be in the second page, and make sure in the first page you are using:

<form method="get" action="yournextpage.htm">

(The only way javascript can pass values from page to page is to use the "get" method, which gives the page that it posts to a querystring). What that does, is it puts all of the form values you're using on the first page into the URL of the second page, like:

http://www.whatever.com/somepage.ext?name=value&name2=value2

The part bolded above (which I'm sure you've seen on many sites), is called the "querystring".

:)

On the second page (assuming you included the script I posted), you could get any variable's value from the querystring by using:

<input type="text" name="blah" value="QueryString('blah')" />

where "blah" is the "name" in the querystring, the QueryString() function will return the value, if it exists.

Hope this helps. :D

P.S. The tutorial I posted should also give you more information on this kind of technique - and it's a must read, especially if you're new to javascript!

You should never feel like an idiot though, and don't be afraid to ask any questions here at all - everyone is new to javascript at one point.

That's what we're here for! Believe me, I still have quite a bit to learn about javascript and a few other programming languages to boot. You never stop learning, you can only get better. :D

barracuda11201
12-06-2002, 02:12 AM
thank you whammy ...

anyway, i found a much easier way to create a new window and have the results displayed in a textbox in that new window ....

///////////////////////////////////////////////////////////////////////////////


function viewShoppingCart(){

results = window.open("", "results","toolbar=1,status=0,width=400,height=400");
parent.results.document.open("text/html");
parent.results.document.write("<html><head><title>profile</title><form name='form2' method='POST'></head><body> ");

displayItems();

parent.results.document.write('<center><p><a href="javascript:close();">Close Window</a></p></center></body></form></html>');
parent.results.document.close();
}

///////////////////////////////////////////////////////////////////////////
in the function called displayItems(); .... i can then use code
such as below which takes the value of a textbox, radio button, whatever..... from the main form to the new window form .... seems much easier to me!! :)

parent.results.document.write("book #1: <input type='text' name='book12'>");

parent.results.document.form2.book1.value = document.Form1.book1.value;

///////////////////////////////////////////////////////////////////////////

beetle
12-06-2002, 04:17 AM
That will work, until you decide you don't want a popup and make it just a regular link. I'm not saying that will happen, of course, but the method whammy and I outlined will work for both

Here (http://www.codingforums.com/showthread.php?s=&threadid=8582&highlight=parseGetVars) is a thread where I helped an individual implement my parseGetVars function, and shows examples of how it can be used to put the data anywhere on the page: as text, in form controls, or even for the document title.

beetle
12-06-2002, 08:47 PM
Oh, and apologies, after looking back I realize my last examlpe had some errors. Here's one I tested.
<html>
<head>
<title>Whatever</title>

<script type="text/javascript">

function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split("&");
var nameVal, val;
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split("=");
val = (typeof nameVal[1] == 'undefined') ? '' : unescape(nameVal[1]);
getVars[unescape(nameVal[0])] = val;
}
return getVars;
}

function setFormValues(f) {
var _GET = parseGetVars();
f.qty.value = (typeof _GET['quantity'] != 'undefined') ? _GET['quantity'] : "";
}

</script>
</head>

<body onload="setFormValues(document.forms[0]);">
<form method="GET">
<input type="text" name="qty" />
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum