Jump to content

Concatenate Autocomplete elements


Recommended Posts

I am able to get the below working on a Submission form with the element set to text box. Is there a way to do the same thing, but with the autocomplete element chosen? So far I have not been able to get it to work when I change to element type from text box to autocomplete. It does not add the entries together

 

Link to comment
Share on other sites

7 minutes ago, MayMusic said:

When you have an autocomplete form element ID of the element changes each time the page loads. So you need to refer to it by name. For instance:

 


var position1 = document.getElementsByName("InsertRecordPosition1")[0].value;

 

Refer to

 

This is what I currently have, it is not joining the field together. It was working before the changes you suggested, just not with autocomplete.

 

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var position1 = document.getElementByName("InsertRecordPosition1")[0].value;
var position2 = document.getElementByName("InsertRecordPosition2")[0].value;

var allpositions = position1 + ","+ position2;

document.getElementByName("InsertRecordAllPositions")[0].value = allpositions;

}

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

Link to comment
Share on other sites

5 minutes ago, MayMusic said:

Only for autocompelete and cascading dropdowns you need to use name you should change

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

to

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

So then this?
 

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var position1 = document.getElementsByName("InsertRecordPosition1")[0].value;
var position2 = document.getElementsByName("InsertRecordPosition2")[0].value;

var allpositions = position1 + ","+ position2;

document.getElementsByName("InsertRecordAllPositions")[0].value = allpositions;

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

Link to comment
Share on other sites

it worked perfectly I appreciate that very much.

I ran into a slight problem however. I have 64 fields that are going to be combined into the Single field. Each field will have a name in them and I currently have it so that it inserts a , in between each entry. Is there a way to have it so that if the field is blank, it doesn't insert a , when it combines the entries?

 I currently get the following UN1, UN2,,,,,,,,UN10,UN11,, etc.

Link to comment
Share on other sites

Ok then you need to have an array. Try this:


 

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var p = new Array(" InsertRecordPosition1", " InsertRecordPosition2", " InsertRecordPosition3", " InsertRecordPosition4");
var allpositions = "";

for (var i = 0; i < p.length; i++) {

var item = document.getElementsByName(p[i])[0].value;
if (item != "") {

allpositions += ","+ item;
}
}
allpositions = allpositions.substring(1);
document.getElementsByName("InsertRecordAllPositions")[0].value = allpositions;

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

 

Link to comment
Share on other sites

It did not combine them into Allpositions

<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var p = new Array(" InsertRecordPosition1", " InsertRecordPosition2", " InsertRecordPosition3", " InsertRecordPosition4", " InsertRecordPosition5", " InsertRecordPosition6", " InsertRecordPosition7", " InsertRecordPosition8", " InsertRecordPosition9", " InsertRecordPosition10", " InsertRecordPosition11", " InsertRecordPosition12", " InsertRecordPosition13", " InsertRecordPosition14", " InsertRecordPosition15", " InsertRecordPosition16", " InsertRecordPosition17", " InsertRecordPosition18", " InsertRecordPosition19", " InsertRecordPosition20", " InsertRecordPosition21", " InsertRecordPosition22", " InsertRecordPosition23", " InsertRecordPosition24", " InsertRecordPosition25", " InsertRecordPosition26", " InsertRecordPosition27", " InsertRecordPosition28", " InsertRecordPosition29", " InsertRecordPosition30", " InsertRecordPosition31", " InsertRecordPosition32", " InsertRecordPosition33", " InsertRecordPosition34", " InsertRecordPosition35", " InsertRecordPosition36", " InsertRecordPosition37", " InsertRecordPosition38", " InsertRecordPosition39", " InsertRecordPosition40", " InsertRecordPosition41", " InsertRecordPosition42", " InsertRecordPosition43", " InsertRecordPosition44", " InsertRecordPosition45", " InsertRecordPosition46", " InsertRecordPosition47", " InsertRecordPosition48", " InsertRecordPosition49", " InsertRecordPosition50", " InsertRecordPosition51", " InsertRecordPosition52", " InsertRecordPosition53", " InsertRecordPosition54", " InsertRecordPosition55", " InsertRecordPosition56", " InsertRecordPosition57", " InsertRecordPosition58", " InsertRecordPosition59", " InsertRecordPosition60", " InsertRecordPosition61", " InsertRecordPosition62", " InsertRecordPosition63", " InsertRecordPosition64");

var allpositions = "";

for (var i = 0; i < p.length; i++) {

var item = document.getElementsByName(p[i])[0].value;
if (item != "") {

allpositions += ","+ item;
}
}
allpositions = allpositions.substring(1);
document.getElementsByName("InsertRecordAllPositions")[0].value = allpositions;

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

 

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
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...