DataCobalt Posted January 26, 2015 Report Share Posted January 26, 2015 Good afternoon, I am attempting to use the Javascript posted in the solutions to combine fields. In my case I have three fields I am looking to combine. Employee_First_Name, Employee_Last_Name, and Employee_ID. The ideal formatting of this would be Lastname, Firstname - EmployeeID (For Example Smith, John - 111111) Here is the script I have that is not currently combining the fields let alone getting into the details of formatting. This is being deployed in a submission datapage. <SCRIPT LANGUAGE="JavaScript"> function concatenate() { var Employee_First_Name = document.getElementById("InsertRecordEmployee_First_Name").value; var Employee_Last_Name = document.getElementById("InsertRecordEmployee_Last_Name").value; var Employee_ID = document.getElementById("InsertRecordEmployee_ID").value; var Employee_Selector = Employee_Last_Name + Employee_First_Name + Employee_ID; document.getElementById("InsertRecordEmployee_Selector").value = Employee_Selector; } document.getElementById("caspioform").onsubmit=concatenate; </SCRIPT> Thank you for your time! Quote Link to comment Share on other sites More sharing options...
LWSChad Posted January 26, 2015 Report Share Posted January 26, 2015 Storing calculated data should be avoided. (in this scenario your calculated data is 100% redundant) Store the data separately and concatenate or calculate on display. On Display: [@field:Employee_First_Name] + ' ' + [@field:Employee_Last_Name] + ' - ' + [@field:Employee_ID] Quote Link to comment Share on other sites More sharing options...
DataCobalt Posted January 26, 2015 Author Report Share Posted January 26, 2015 Storing calculated data should be avoided. (in this scenario your calculated data is 100% redundant) Store the data separately and concatenate or calculate on display. On Display: [@field:Employee_First_Name] + ' ' + [@field:Employee_Last_Name] + ' - ' + [@field:Employee_ID] The calculated field is going to be used as the field for a dropdown selection. Otherwise companies with more than one Smith are guessing when trying to add records for one of them. Quote Link to comment Share on other sites More sharing options...
Jan Posted January 27, 2015 Report Share Posted January 27, 2015 Hello DataCobalt, Maybe, you can use Lookup tables and Cascading drop-down lists to allow select the required Smith. Does it work for you? Quote Link to comment Share on other sites More sharing options...
DataCobalt Posted January 27, 2015 Author Report Share Posted January 27, 2015 Hello DataCobalt, Maybe, you can use Lookup tables and Cascading drop-down lists to allow select the required Smith. Does it work for you? Good morning Jan, That was an option I had considered, but the ideal would be to have the customer have one drop-down that lists the individual. Having data captured in this manner would also be beneficial because we could make that field unique and ensure that our database didn't contain duplicate employees. Quote Link to comment Share on other sites More sharing options...
Jan Posted January 28, 2015 Report Share Posted January 28, 2015 Hello DataCobalt, As far as I know, it is impossible to use Autonumber of a record on a Submission Form, because the Autonumber is created only after the record is successfully created. You can use a Single Update Form and AutoSubmit to fill the Employee_Selector field. The idea is: 1) On the Submission Form a user enters Employee_First_Name and Employee_Last_Name on the "Select Fields" step, check the "On exit, pass AutoNumber ID field as parameter" checkbox on the "Destination and Triggers" step, select "Go to a new page" and select the page, where the Single Update Form is deployed. 2) On the Single Update Form on the "Single Record Update" step, enter [@InsertRecordEmployee_ID] as Parameter Name on the "Configure Fields" step, select the "Text Field" Form element for fields Employee_First_Name, Employee_Last_Name, and Employee_Selector Add Header&Footer element Add the following code to the Header element: <div align="center"> <p>Processing...</p> </div> Add the following code to the Footer element: <SCRIPT LANGUAGE="JavaScript"> var Employee_First_Name = document.getElementById("EditRecordEmployee_First_Name").value; var Employee_Last_Name = document.getElementById("EditRecordEmployee_Last_Name").value; var Employee_ID = [@InsertRecordEmployee_ID]; var Employee_Selector = Employee_First_Name + ", " + Employee_Last_Name + " - " + Employee_ID.toString(); document.getElementById("EditRecordEmployee_Selector").value = Employee_Selector; if (document.getElementById("caspioform")) { document.getElementById("caspioform").style.display = 'none'; setTimeout('document.forms["caspioform"].submit()',1000); } </SCRIPT> Now a user enters Employee_First_Name and Employee_Last_Name, then the user sees "Processing..." and the "Employee_Selector" value is added to the table. I hope, it helps. Quote Link to comment Share on other sites More sharing options...
DataCobalt Posted January 28, 2015 Author Report Share Posted January 28, 2015 Hi Jan, Thank you for the response, I have a few datapages that use a similar method to store calculated data. I think this is what I will wind up doing for the employee record as I'm not sure I can get the correct formatting with Javascript even if I can get the fields to combine. The Employee_ID is not actually the key field (Employee_Record_ID is the autonumber) so I was hoping it could be accomplished with Javascript. Employee_ID is for a company's internal ID system that they assign to their own employees. Quote Link to comment Share on other sites More sharing options...
Jan Posted January 29, 2015 Report Share Posted January 29, 2015 Hello DataCobalt, Then you can add two symbols to your JavaScrit: <SCRIPT LANGUAGE="JavaScript"> function concatenate() { var Employee_First_Name = document.getElementById("InsertRecordEmployee_First_Name").value; var Employee_Last_Name = document.getElementById("InsertRecordEmployee_Last_Name").value; var Employee_ID = document.getElementById("InsertRecordEmployee_ID").value; var Employee_Selector = Employee_Last_Name + ", " + Employee_First_Name + " - " + Employee_ID; document.getElementById("InsertRecordEmployee_Selector").value = Employee_Selector; } document.getElementById("caspioform").onsubmit=concatenate; </SCRIPT> If the Script code does not work, could you please provide the URL of your page or FoemElements of every field? Quote Link to comment Share on other sites More sharing options...
DataCobalt Posted January 29, 2015 Author Report Share Posted January 29, 2015 Hey Jan, thank you for that syntax on adding the characters. The Javascript wasn't working but it turns out it was an issue of two capital letters that were in the script that weren't in the field names (the two "N"s in the Name fields). Once I had that solved, and with this addition, it comes out exactly as I had hoped! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.