Jump to content
  • 0

Combo field again


sylvie
 Share

Question

There is a topic elsewhere in this forum called ? Combo ? Fields posted by casamurphy.

As I am not sure if this topic is still active, I am posting my question here:

I was very interested to read about creating a combo field in that post.

I tried to recreate the script, but it is not working.

I have two fields in my table: Firstname and Lastname. I am trying

to combine these two fields into a third field (Firstname + Lastname).

I understand that a script needs to be created, but I am not sure where this script should reside.

Can you, please, help?

Link to comment
Share on other sites

19 answers to this question

Recommended Posts

  • 0

Below is a script casamurphy posted to this forum on Nov 29, 2006 with a slight edit suggested by carol on Nov 30, 2006. This script ought to be modified to your specific needs. To use this solution, highlight to copy the code provided below and then paste it inside the HTML Footer section of your WebForm DataPage.

<SCRIPT LANGUAGE=\"JavaScript\"> 

<!-- This function will take the values of three fields and append them one to another and store that string into a fourth field.--> 

function concatenate() 
{ 
//(1) Retrieve the value of the field Name and store in a variable name. 
var name = document.forms[0].InsertRecordName.value; 

//(2) Retrieve the value of the field Prefix and store in a variable prefix. 
var prefix = document.forms[0].InsertRecordPrefix.value; 

//(3) Retrieve the value of the field URL and store in a variable url. 
var url = document.forms[0].InsertRecordURL.value; 

//(4) Retrieve the value of the field Suffix and store in a variable suffix. 
var suffix = document.forms[0].InsertRecordSuffix.value; 

//(5) Create the string and define a variable with that value. 
var link = name+prefix+url+suffix; 

//(6) Post the string to the targeted field. 
document.getElementById(\"InsertRecordLink\").value = link; 
} 

//(5) On submitting the webform, the function calculate is executed. 
document.forms[0].onsubmit=concatenate; 

</SCRIPT>

Disclaimer: This is a user-supplied JavaScript solution and should be Used at your own risk! By using this or any other script you accept all responsibility and acknowledge that they are not a feature of Caspio's platforms and as such are provided \"as is\" without any warranties, support or guarantees.

Link to comment
Share on other sites

  • 0

Many, many thanks for your reply.

Yes, I did copy the script into the footer, but it does not work.

So I would like to find out what I am doing wrong.

I have two fields Firstname and Lastname in my table called Students.

I also added a field called Name to that table.

I created a Web Form to capture submissions. I modified the script

to include Firstname and Lastname to populate the third field called Name.

I pasted this script inside the HTML footer:

function concatenate()

{

//(1) Retrieve the value of the field Firstname and store in a variable firstname.

var firstname = document.forms [0].InsertRecordFirstname.value;

//(2) Retrieve the value of the field Lastname and store in a variable lastname.

var lastname = document.forms[0].InsertRecordLastname.value;

//(3) Create the string and define a variable with that value.

var name = firstname+lastname;

//(6) Post the string to the targeted field.

document.getElementById(\"InsertRecordName\").name;

}

//(5) On submitting the webform, the function calculate is executed.

document.forms[0].onsubmit=concatenate;

I would be grateful for your help.

Sylvie

Link to comment
Share on other sites

  • 0

This is what I have in the html footer and no results.... any help?

function concatenate()

{

//(1) Retrieve the value of the field City and store in a variable city.

var city = document.Forms [0].InsertRecordCity.value;

//(2) Retrieve the value of the field Zip and store in a variable zip.

var zip = document.Forms[0].InsertRecordZip.value;

//(3) Create the string and define a variable with that value.

var cityzip = zip+city;

//(6) Post the string to the targeted field.

document.getElementByid(\"InsertRecordName\") = cityzip;

}

//(5) On submitting the webform, the function calculate is executed.

document.Forms[0].onsubmit=concatenate;

except nothing happens LOL

Link to comment
Share on other sites

  • 0

from what i just read javascript has to be in the header, body or called as an external script.

perhaps someone can be clear on exactly how to write this, every variation i have tried does not work.

I have search the web and can't find this simple answer. I want to combine a user entered field called Zip with a user entered field called City into a hidden field (or not) called cityzip.

I will then use this field to search for places allowing the input for field cityzip as "contains" (either city or zip)

Link to comment
Share on other sites

  • 0

The error is on the line document.getElementByid(\"InsertRecordName\") = cityzip;

Looking at the original code, it should be

document.getElementById("InsertRecordName").value = cityzip;

What is the hidden field that you try to assign the concatenated value into? Base on the line above, this fields should be called Name. Now if you have it with a different name you have to modify this line and replace Name in InsertRecordName with the field name you have.

The Java Script could be either inserted in the DataPage footer block or an HTML block at the end of all field elements in "Field Configuration" wizard screen.

Best,

Bahar M.

Link to comment
Share on other sites

  • 0

this is exactly what i have and it still doesn't work

function concatenate()

{

//(1) Retrieve the value of the field City and store in a variable city.

var city = document.Forms [0].InsertRecordCity.value;

//(2) Retrieve the value of the field Zip and store in a variable zip.

var zip = document.Forms[0].InsertRecordZip.value;

//(3) Create the string and define a variable with that value.

var cityzip = city+" "+zip;

//(6) Post the string to the targeted field.

document.getElementById("InsertRecordCityzip").value = cityzip;

}

//(5) On submitting the webform, the function calculate is executed.

document.Forms[0].onsubmit=concatenate;

http://b3.caspio.com/folderlogout/

Link to comment
Share on other sites

  • 0

Hello,

This is what I have on my DataPage and it works fine. Note that my City, Zip and ZipCity are all of type Text in the table. Also I am using ZipCity as hidden field on the DataPage. Upon submit, the ZipCity field gets populated with the concatenated field. Hope it works for you.

--------------------------------------------------------------------

function concatenate()

{

var city = document.getElementById("InsertRecordCity").value;

var zip= document.getElementById("InsertRecordZip").value;

var cityzip = city+ " " +zip;

//alert("Cityzip: " + cityzip );

document.getElementById('InsertRecordZipCity').value = cityzip;

}

document.forms[0].onsubmit=concatenate;

-------------------------------------------------------------------

Regards,

-SO

Link to comment
Share on other sites

  • 0

Okay your scripts worked great! Thank you. I replaced your field with my fields and no problem. Now do you have a clue as to why it won't work in my 'search and modify" data page. all the data gets changed but the zipcity field gets blanked out. Its updating it with a blank value, weird.

Link to comment
Share on other sites

  • 0

Hi,

On the Search and Report(S/R) DataPage, the prefix to address the fields on the form is EditRecord. So the JS on a S/R would be:

function concatenate()

{

var city = document.getElementById("EditRecordCity").value;

var zip= document.getElementById("EditRecordZip").value;

var cityzip = city+ " " +zip;

//alert("Cityzip: " + cityzip );

document.getElementById('EditRecordZipCity').value = cityzip;

}

document.forms[0].onsubmit=concatenate;

Best,

-SO

Link to comment
Share on other sites

  • 0

Hi all, 

 

Just to give you an update, Caspio released new features last year. One of these is the Calculated Value in the Submission Form. You don't need to insert custom script on your DataPage to concatenate two fields. The Calculated Value form element generates dynamic calculations that automatically update as users interact with your form. 

Please see screenshot below: 

image.png.4a87a74d53f671972a28b8768c354f8c.png

 

You can get more information on this link: https://howto.caspio.com/datapages/datapage-components/calculated-values/

 

-kristina

Link to comment
Share on other sites

  • 0

Hi Just to add to the previous comment above,  In the new release of Caspio version 17.0 , you can now add the Calculated Value form element to Update Forms and Details Pages to generate dynamic calculations as users interact with your forms. Previously, this feature was only available in Submission Forms. You may also check this link about calculated value: https://howto.caspio.com/datapages/datapage-components/calculated-values/

Also, you can Concantenate two fields in your Table using a Formula field.

Concatenate.thumb.png.1a4ce5f70b1ef1d6a00e354632e9d4a1.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...