Jump to content

Javascript concatenate on dropdown lookup?


Recommended Posts

I have a capture datapage that has two fields that are dropdown > custom values and the javascript concatenate works fine.

On that same capture datapage I have three fields that are dropdown > lookup table or view and the javascript concatenate DOES NOT work! I have placed some javascript in the capture datapage to see the element names and values and see that the fields (elements) are populated with data upon initialization, you can change the values via the dropdown > lookups, but concatenate just will not work.

I can't even get the dropdown lookup value to populate another field so I am guessing the values are evaluated and written after the javascript to populate another field or concatenate is executed. Is this the case? Can I not use values from dropdown lookup to concatenate (even though I can use dropdown custom values)? Can anybody help?

Thanks,

Jeff

Link to comment
Share on other sites

Hi Jeff,

I tested the concatenation JavaScript (viewtopic.php?f=14&t=12233) on both "custom value" dropdowns and "lookup table or view" dropdowns and both of them work for sure.

You mentioned that one dropdown is not even populating values from the lookup table or view. Maybe you wanted to check the settings of the dropdown to make sure you selected the proper field and also open the lookup table to make sure the source field is not blank. No matter using which source, how the dropdowns are populated doesn't have any association with the Javascript. What the Javascript does is simply capturing the values appears in the dropdown and concatenate them. And if there's no value appears in the second dropdown, the results of concatenation should be the value of the first dropdown only.

Another suggestion is to check the field name and parameter name used in the code to make sure of consistency. You can also paste the URL here for us to help you to troubleshoot the code.

Link to comment
Share on other sites

Thanks for your reply shengnandou. I have tried several things, but none seemed to work, so here's the code in the HTML footer:

function concatenate1()

{

var hours = document.getElementById("InsertRecordUnit_Duration_Hours").value;

var minutes = document.getElementById("InsertRecordUnit_Duration_Min").value;

var duration = hours+":"+minutes;

document.getElementById("InsertRecordDuration").value = duration;

}

function concatenate2()

{

var hours2 = document.getElementById("InsertRecordUnit_Duration_Hours").value;

var minutes2 = document.getElementById("InsertRecordUnit_Duration_Min").value;

dechours = hours2 * 1;

decmin = minutes2 / 60 ;

var decduration = dechours+decmin;

document.getElementById("InsertRecordUnit_Duration").value = decduration;

alert("Thanks! It worked!");

}

function concatenate3()

{

var RMS1 = document.getElementById("InsertRecordRMS_Number").value;

alert(RMS1);

var ForId1 = RMS1+3;

alert(ForId1);

document.getElementById("InsertRecordRMS_Number").value = ForId1;

}

function concatenate()

{

concatenate1();

concatenate2();

concatenate3();

}

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

The alerts in concatenate3 function don't come up, so I gather they are not evaluating and the field is never populated.

The link for the page is: http://b4.caspio.com/dp.asp?AppKey=56df ... 83404abeb4

username: brad

pw: 1234

Link to comment
Share on other sites

Hi,

The problem of the concatenate3 function is that the Admin/RMS field's ID not equals to "InsertRecordRMS_Number" which makes this sentence stops working:

var RMS1 = document.getElementById("InsertRecordRMS_Number").value;

Please note the field is a dropdown field the ID of which is contently changing each time you load the page. However, the name of a Caspio form dropdown field is static. Change the previous sentence to

var RMS1 = document.getElementsByName("InsertRecordRMS_Number")[0].value;

should make it to work. Hope this helps.

Link to comment
Share on other sites

WOW! That worked! Thank you so much!!!

I do have two more questions...

1. Is there documentation on when to use getElementsByName or getElementByID?

2. Why did I have to use getElementsByName("InsertRecordfieldname")[0].value to populate the hidden text field in concatenate3 function? I was able to use getElementByID in the two previous functions, but this one required similar context within the concatenate3 function in order to work properly. Is that a rule?

Again, THANK YOU! This was kicking me in the head for three weeks!

Link to comment
Share on other sites

Hi,

You are so welcome. Glad you've manged it to work. One mistake I made in my last response, what I mean is a cascading dropdown field (this applies for both parent field and child field) has changing 'ID' but static 'name'.

Sorry but there's no documentation on this. What I suggest is to install an add-on called firebug into your Firefox browser and use it to track form elements and debug your code. After opening firebug, you can simply focus on any object and check the name, ID or any other attributes of it (see screenshot), then decide on how to refer to the element in your code.

Link to comment
Share on other sites

  • 3 years 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...