Jump to content
  • 0

Run Virtual Change function only if field value is null


DesiLogi

Question

Hi,

I'm trying to run a 'change' function on a virtual field ONLY when a regular field is Null. This is in a submission form. 

The code I have below seems to run automatically when the form is opened, I guess because the virtual field is a cascading dropdown so it's 'changing' when the form is loaded, based on the parent field. 

I only want this code to run if the 'ItemID' field (ItemID is not the parent of the cascading Virtual9) is null. If it is not null then I need this code to not run at all, even onload. I've tried a bunch of different 'if' scenarios but can't get it to work. Hopefully someone can help..

<script>
$("[name='cbParamVirtual9']").change(function(){

var itid = document.getElementsByName("cbParamVirtual9")[0].value;
var item = document.getElementsByName("InsertRecordItemID")[0].value

if (item !== null)
{

document.getElementsByName("InsertRecordItemID")[0].value = itid;

}
}
);

</script>

NOTE: I ran an alert window to make sure the values in Virtual 9 are being gotten and used- they are and they are put in the ItemID field as needed on the Virtual 9 change. The problem is that when ItemID is not null on the form's load (it receives and external parameter, if there is one) the code still runs. This will overwrite the ItemID's external parameter received. 

Also, I'm not sure why ItemID works with getElementsbyName instead of getElementbyID because it's just a text field and not dropdown,list,cascading, etc. But the code didn't work unless I used getElementsbyName.. 

I think I just need to add the correct 'if' expression that runs or doesn't run the 'Change' function next. 

<script>
var item = document.getElementsByName("InsertRecordItemID")[0].value;
  
<!-- right here I need an if (item !== null) to then run the change(function(){ but that if it's not null to not run the change(function(){ -->
  
$("[name='cbParamVirtual9']").change(function(){

var itid = document.getElementsByName("cbParamVirtual9")[0].value;
document.getElementsByName("InsertRecordItemID")[0].value = itid;

}
);

</script>

 

Link to comment
Share on other sites

1 answer to this question

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.

Guest
Answer this question...

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