Jump to content

Conditional JavaScript does not seem to get virtual cascading text field value


Recommended Posts

Hi everyone,

I'm fairly new to the world of JavaScript and have the following scenario on a submission page:

During submission, my users select a business client using an AutoComplete field. Once they selected a client,  two virtual fields pull two values for this client from an external table. These lookups are set up using cascading text field. On the same DataPage, there is a radio button with two options. Should the two virtual fields remain blank (basically meaning that there is no value for either of the fields for this client in the external table), the 2nd radio button option should be selected and the field hidden to prevent user interaction.

The hiding and selection part works fine, but it seems that I'm not able to get the value from the virtual fields and my script stops working as soon as I add the condition that involves the value of any of the two virtual fields:

 

<script type= "text/javascript">

function AMFCheck()
{ 

var AMF1 = document.getElementById('cbParamVirtual12')[0].value;
var AMF2 = document.getElementById('cbParamVirtual13')[0].value;

if (AMF1 == "" && AMF2 == "" )
{ 
document.getElementById("InsertRecordAMF_payable1").checked = true;
document.getElementById("InsertRecordAMF_payable").style.display = "none";
}
}
document.getElementById("caspioform").onchange=AMFCheck;
</script>

 

I'd be really grateful for any help.

 

Thanks,

Christof

Link to comment
Share on other sites

Cascading fields lose their static ID, so if it's a cascading text field the ID will change from "cbParamVirtual12" to something like "cbParamVirtual12_jhdas068fsda0t67f8"

Try 

var AMF1 = document.getElementsByName('cbParamVirtual12')[0].value;

rather than

var AMF1 = document.getElementById('cbParamVirtual12')[0].value;
Link to comment
Share on other sites

  • 8 months later...
On 8/25/2016 at 5:12 AM, ezIQchad said:

Cascading fields lose their static ID, so if it's a cascading text field the ID will change from "cbParamVirtual12" to something like "cbParamVirtual12_jhdas068fsda0t67f8"

Try 


var AMF1 = document.getElementsByName('cbParamVirtual12')[0].value;

rather than


var AMF1 = document.getElementById('cbParamVirtual12')[0].value;

This is not working for cascading virtual text fields

Thank you

Link to comment
Share on other sites

  • 1 year later...

Hey, @ezIQchad. Any chance you're still active? I am having an issue similar to this. I was having a problem passing parameters interally to a popup, and because of this post I found its because Cascading Fields lost their static id. However, I believe the code I am using is using ID selectors and I am not sure how to change it to name. (I think its jQuery)

Link to comment
Share on other sites

  • 3 years later...
On 8/24/2016 at 3:12 PM, LWSChad said:

Cascading fields lose their static ID, so if it's a cascading text field the ID will change from "cbParamVirtual12" to something like "cbParamVirtual12_jhdas068fsda0t67f8"

Try 

var AMF1 = document.getElementsByName('cbParamVirtual12')[0].value;

rather than

var AMF1 = document.getElementById('cbParamVirtual12')[0].value;

Can you copy past the full code and correct it for us?

Link to comment
Share on other sites

Hi @AveEd - you can use querySelector. Here are some examples:

document.querySelector("input[name='cbParamVirtual1']")

OR

document.querySelector("input[id*='cbParamVirtual1']")

OR

document.querySelector("[name='cbParamVirtual1']")

For more information, you can check this link: https://www.w3schools.com/jsref/met_document_queryselector.asp

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