Jump to content

Js: Concatenate/combine Two Fields Into One Field


Recommended Posts

I found this script in the "help function". To be used in a "submission form". It says that I can replace INSERTRECORD With EDITRECORD if a want to to use the script in a details page of a Search an Report Datapage. I have a problem With that. Is there something more I have to do?

 

 

<script Language="JavaScript">

 

function concatenate()

 

{

var position1 = document.getElementById("InsertRecordPosition1").value

var position2 = document.getElementById("InsertRecordPosition2").value

 

var allpositions = position1 + position2;

 

document.getElementById("InsertRecordAllPositions").value=allpositions;

 

}

 

document.getElementById("caspioform").onsubmit=concatenate;

</SCRIPT>

 

Link to comment
Share on other sites

Hello Leadma,

 

In the script, semicolons after some lines are absent.

You can try the code like:

<script language="JavaScript">
function concatenate()
{
var position1 = document.getElementById("InsertRecordPosition1").value;
var position2 = document.getElementById("InsertRecordPosition2").value;
var allpositions = position1 + position2;
document.getElementById("InsertRecordAllPositions").value=allpositions;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>
Link to comment
Share on other sites

  • 4 months later...

The solution here feels like the answer I am looking for, but I need a little help to implement.  I have a first name field and a last name field on my submission form.  I would like to create a new value for "full name" by concatenating the two.  This needs to happen without necessarily "passing" the parameters since this is collected on the last page the user will interact with.

 

I'm not really a JS person.  I just know what I've learned implementing things here and there on Caspio.    So my question is... If my First name field is FName, my last name field is LName and I want to create UserName, how specifically would I alter the code mentioned in this post?  Do I use Position1?  Substitute it?  Use "caspioform"?  Substitute it with a data page name?

 

Sorry the question is so basic, but that's where I am.

 

Thank you for any help.

 

Link to comment
Share on other sites

Hello tclemendor,

 

If you work with a Submission form, you can copy the script and change only names like:

InsertRecordPosition1 -> InsertRecordFName

InsertRecordPosition2 -> InsertRecordLName

InsertRecordAllPositions -> InsertRecordUserName

 

There is JS Guide, maybe it can help.

Link to comment
Share on other sites

Jan,

 

Does that mean that I can't add a third position and make give it a default value of a space (" ")? I modified the script as below...

 

<script language="JavaScript">

function concatenate()
{
var position1 = document.getElementById("InsertRecordFname").value;
var position2 = document.getElementById("InsertRecordSpace").value;

var position3 = document.getElementById("InsertRecordLName").value;
var allpositions = position1 + position2 + position3;
document.getElementById("InsertRecordAllPositions").value=allpositions;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

 

I made the field "Space" hidden field with a default value on load of " ".  But that value does not save.  When go back there is no space in the field.  Workarounds?

 

t

Link to comment
Share on other sites

  • 10 months later...

I hope that someone can help. I am trying to implement this script in my datapage, but it will not work. I copied the following code into the footer of my datapage:

<SCRIPT LANGUAGE="JavaScript">
function concatenate()
{
var position1 = document.getElementById("InsertRecordPosition1").value;
var position2 = document.getElementById("InsertRecordPosition2").value;
var allpositions = position1 + position2;
document.getElementById("InsertRecordAllPositions").value = allpositions;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

 

The following fields are in my table:

position1

position2

allpositions

 

When I complete my form it will not combine position1 and position2 as it is supposed too. I am testing the page deployed on my server. I also tried testing it not deployed and neither way will work.

 

In my datapage I have included the field "allpositions" as a hidden field. What am I doing wrong?

 

Please help. Thanks

Link to comment
Share on other sites

Good evening, Michael!

 

How are you doing?

 

I'm learning the JavaScript now, so, I think, capital letters are a problem. Names of your fields don't contain them, but the code does.

 

This code should work:

 

<SCRIPT LANGUAGE="JavaScript">
function concatenate()
{
var position1 = document.getElementById("InsertRecordPosition1").value;
var position2 = document.getElementById("InsertRecordPosition2").value;
var allpositions = position1 + position2;
document.getElementById("InsertRecordAllPositions").value = allpositions;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

 

I'll be grateful, if you tell me if the code works.

 

Have a nice day!

Link to comment
Share on other sites

  • 1 month later...

I am trying to use Concatenate on a Details page with no luck. I have changed "InsertRecord" to "Edit Record", but still not not working. Below is the code.
 

<SCRIPT LANGUAGE="JavaScript">
 
function concatenate()
{
var position1 = document.getElementById("EditRecordDate").value;
var position2 = document.getElementById("EditRecordCheck_Number").value;
var position3 = document.getElementById("EditRecordLocation").value;
 
var allpositions = position1 + position2 + position3;
 
document.getElementById("EditRecordLookupID").value = allpositions;
 
}
 
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

 
Any suggestions will be appreciated.
 
Thank you

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 year later...

HI I am not a java script person but I thought Id add my 2cents

If you want to combine 2 fields in to one, you can do it without Java script (sort of).  In my app a user has to select a gym they go to via a drop down of preselected data in field1.  If they select other in field 1 it is disabled, and they enter a gym in field 1.  These 2 fields will be passed to my page 2 sign up form in a hidden field that will receive both (but one will be blank because it is disabled)

To use your situation:

First take the 2 fields and pass them to a single record update page on page 2 for example; when you submit the form where it says destination after submission, select go to a new page (page2) - Page 2 will have the single record update that will receive the 2 parameters into 1 field

pass  .../mywebsite.com?Full_Name=[@field:First_Name] [@field:Last_Name] to page 2 (space between the 2 fields)

On Page 2, Make Full Name hidden and set to receive External Field; in this case [@field:Full_Name]

Now the second page will receive the first and last name as 1 item!

You would still have to submit page 2 and you could hide this (using Java) and then set page 2 to go to the page that page 1 was supposed to go to.  Hope this helps

Link to comment
Share on other sites

  • 1 year later...

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
Reply to this topic...

×   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...
×
×
  • Create New...