Jump to content
DesiLogi

Combine 2 fields into 3rd on Inline Insert

Recommended Posts

I'm trying to figure out how to use a concatenate function that works in a submission form for a tabular inline insert. I believe Ajax has to be disabled for this (I did that). 

I have the below in a custom.js file accessible by the page the datapage is hosted in:

//concate for the simple combination field
function f_secondcombination(part1, part2, comb){
$("[name='"+comb+"']").val($("[name='"+part1+"']").val()+"_"+$("[name='"+part2+"']").val());
}

In the datapage itself I'm using, in the header:

<div id="cb_sup">

In the footer of the datapage:

</div>
<script>

$("#cb_sup form”).click(function(){

f_secondcombination('InsertEditRecordCompanyID', 'InsertEditRecordArea', 'InsertEditRecordCompanyID_Area');

});

$(document).ready(function(){
var v_errmes = "This Area already exists for this Company. Please provide a different one.";
f_modify_err_message("cb_value_present", "cb_not_valid_info",v_errmes);

});
</script>

 

The other solution I'm trying is having only this (so it's not referencing the custom.js file) in the footer:

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var CompanyID = document.getElementById("InsertEditRecordCompanyID").value;
var Area = document.getElementById("InsertEditRecordArea").value;

var CompanyID_Area = CompanyID + Area;

document.getElementById("InsertEditRecordCompanyID_Area").value = CompanyID_Area;

}

document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

Neither of these is working:

When the user adds a new record (in inline insert) it should combine the 'CompanyID' field with the 'Area' field and put that in 'CompanyID_Area' (which will be a unique field in the table so duplicates can be checked). If someone can please help troubleshoot this I'd very much appreciate it. 

Share this post


Link to post
Share on other sites

Hello DesiLogi,

I cannot check your script right now, so it is just my opinion.
I think that your script does not works, because you use invalid names for inline fields. Please pay your attention, that prefix for inline insert fields is InlineAdd, and for inline update it is InlineEdit, but it isn't InsertRecord.

Thanks

Share this post


Link to post
Share on other sites

Hi kRv,

Ok thanks for pointing that out. Someone at Caspio gave me the prefixes specifically several months ago when I first tried this- that's why I was using them. But it makes sense they should be different. I'll give that a shot and post if I get it working this way. 

Share this post


Link to post
Share on other sites

I m not sure about the first code but for the second one try:

 

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var CompanyID = document.getElementsByName("InlineAddCompanyID")[0].value;
var Area = document.getElementsByName("InlineAddArea")[0].value;

var CompanyID_Area = CompanyID + Area;

document.getElementsByName("InlineAddCompanyID_Area")[0].value = CompanyID_Area;

}

document.getElementById("Mod0InlineAdd").onclick=concatenate;
</SCRIPT>

Put this code in HTML Block at the end of all elements.

Share this post


Link to post
Share on other sites

Hi MayMusic,

Thanks for the help with the code. I've tried it but am getting an error message for the combined field CompanyID_Area. This is the 'Unique' field in the table and it has to be on the datapage results in order to allow Inline Add. I've attached the error message- perhaps the js needs to run before the 'Add' button is clicked?

error msg areas add.png

Share this post


Link to post
Share on other sites

I tried this code and it worked for me

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{

var CompanyID = document.getElementsByName("InlineAddRed")[0].value;
var Area = document.getElementsByName("InlineAddGreen")[0].value;

var CompanyID_Area = CompanyID + Area;
alert(CompanyID_Area );
document.getElementsByName("InlineAddallcolor")[0].value = CompanyID_Area;

}

document.getElementById("Mod0InlineAdd").onclick=concatenate;
</SCRIPT>

 

Share this post


Link to post
Share on other sites

Actually, I just got it to work finally. The problem is that Ajax has to be disabled and that takes away a lot of functionality on the datapage so it's a real trade off as to whether it's worth it. But thanks very much for your help on this. If anyone needs the final code I used (so they can modify it for themselves, it's below.

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{

var CompanyID = document.getElementsByName("InlineAddCompanyID")[0].value;
var Area = document.getElementsByName("InlineAddArea")[0].value;

var CompanyID_Area = CompanyID+"_"+Area;
alert(CompanyID_Area );
document.getElementsByName("InlineAddCompanyID_Area")[0].value = CompanyID_Area;

}

document.getElementById("Mod0InlineAdd").onclick=concatenate;
</SCRIPT>

 

Share this post


Link to post
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
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...