Home  |  About  | Last |  Submit  |  Contact
AllQuests.com




Previous Question:  Need some advice on multiple domians  Just Starting Your DesignNext Question:  Using PHP MySQL  Just Starting Your Design
Question Script to copy multiple fields to one. ( SitePoint Forums Just Starting Your Design )
Updated: 2008-08-12 07:19:11 (9)
Script to copy multiple fields to one.

I am creating a HTML form. It has a several fields that once data is typed in them, I want to somehow have all these field be copied and placed in a single field, seperated by a - . For example.

Field1: Name
Field2: Phone
Field3: Location
Field4: Problem

I then want a script, activated by a button to copy the values typed in each of the 4 above fields and placed in another field like:

Field5: Name - Phone - Location - Problem

Any ideas? Thanks for any input you may provide.

Answers: Script to copy multiple fields to one. ( SitePoint Forums Just Starting Your Design )
Script to copy multiple fields to one.

You want the fifth field to be inserted in a mysql db?

Mike

ALSLG

Script to copy multiple fields to one.

Mike,

Yes, it will be on the same form, however, the field I would like to have it pasted in is on inline frame within the page. The values of the few fields will be pasted into the one field with seperators between each value. This final value in this field will be sent via a cgi script to alphanumeric pagers. Thanks for any help you may provide.

svdorr

Script to copy multiple fields to one.

This can be done with a javascript, but I'm wondering why don't you send the actual form to the cgi program that can format the message and send it.

BTW, if the fifth field is in an iframe, it's not the same form because the content of the iframe is an external file.

Mike

ALSLG

Script to copy multiple fields to one.

yes jscript..
<form name="form">
<input type="text" name="name">
<input type="text" name="phone">
<input type="text" name="location">
<input type="text" name="problem">
<input type="button onClick="javascript:merge()">
<script language="javascript">
function merge() {
var split = " - ";
var name = document.form.name.value;
/*and so forth..*/
var merge = name + split + phone + split + etc..;
</script>
should/maybe not work. havent done jscript in a while..

InQuE

Script to copy multiple fields to one.

Here's some code. I assume that your input types are all text and that you give a name to the iframe. But this is generic script:

Code:
<script language="javascript">
function copyVals(obj){
var message="";
   for(i=0; i<obj.length; i++){
   if(obj[i].type=="text"){
         message += obj[i].value+" - ";
     }
   }
sendframe.sendit.paged.value=message;
return false;
}
</script>

<!-- In you form you have this: -->
<form onsubmit="return copyVals(this)">
sendframe.sendit.mess.value refers to a textarea (name="paged") in a form (name="sendit") within the iframe (name="sendframe"). The downside of this code is that you'll get a "-" at the end of the message. If this is a problem, you'll have to copy the values of the inputs one by one.

Mike

ALSLG

Script to copy multiple fields to one.

Thank you ALSLG and InQuE. Both of you ideas look very promising. I will be taking a look at it later this morning. Thanks again for all your help.

svdorr

Script to copy multiple fields to one.

Another quick question. Is there a way to to use the onsubmit event handler to write the form results to a text file?

svdorr

Script to copy multiple fields to one.

With client side script, no. But you can change your cgi script to write to a texte file before or after sending the pager.

Mike

ALSLG

Script to copy multiple fields to one.

That would work, except I won't have access to modify the paging cgi script to write to text first. I know I can have only one Action= in the form, so can I (and how) create my own CGI, that first writes to the text file, then calls the other CGI on the paging server? If so, how do you call another CGI script within a CGI script?

Thanks.

svdorr

Previous Question:  Need some advice on multiple domians  SitePoint Forums  Just Starting Your DesignNext Question:  Using PHP MySQL  SitePoint Forums  Just Starting Your Design

- Source: Script to copy multiple fields to one. SitePoint Forums Just Starting Your Design
- Previous Question: Need some advice on multiple domians SitePoint Forums Just Starting Your Design
- Next Question: Using PHP MySQL SitePoint Forums Just Starting Your Design