How to script a contains condition in client script?

E_19
Giga Expert

Hi All,

I have having trouble scripting a condition that will check if my value contains a certain value.

This is on incident and the field to check is reference Company name field from core_company table.

I have retrieved the value using Ajax call and now I want to check if it contains a value like Dutch Re

if(g_form.getValue('gr.name') ????? 'Dutch Re')

I have read upon using indexOf but may attempts trying to use it failed. Idea is if IndexOf finds < -1 it should indicate the value is there

and then I want to show or hide section tabs.

If anyone can advise or have another suggestion that be greart.

Thanks

Ellie

1 ACCEPTED SOLUTION

sujalavemula
Kilo Guru

and correct the condition to       ---     if(g_form.getValue('gr. name').indexOf('Dutch Re') > -1)


View solution in original post

6 REPLIES 6

sujalavemula
Kilo Guru

try using variablename.indexof('Dutch re') > -1 or variablename.indexof('Dutch re') >= 0



to hide or show section g_form.setSectiondisplay('name of the section',true or false);


Hi Sujala,



Thanks for replying but how would I have to construct the if statement?



I have tried if(g_form.getValue('gr. name').IndexOf (('Dutch Re') >-1  


but that didn't do anything.



Many Thanks,


Ellie


its the syntax .. i should be small case. its   -- indexOf() function.


and does gr.name variable exist on the form or its a result of any table query



try displaying the value of gr.name   and see if it is empty or its Dutch re


dvp
Mega Sage
Mega Sage

indexOx function is available only for array type not to string



try using split function like below



var arr = str.split('Dutch re');



if(arr.length >1)