Highlighted

Javascript works in Designer preview mode, but not when invoked via process

andygoldstein

19-11-2008

I have a fragment consisting of a subform and a text object. The subform has the following Javascript for its initialize event:



-----

var cars = $data.input.cars.car.all;



var showMe = false;



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

if(cars.item(i).color && cars.item(i).color.value == 'RED')

{

showMe = true;

break;

}

}



if(!showMe) {

this.presence = 'hidden';

}

-----



The code is supposed to loop through all my input XML data's cars, see if each car has a color element, and if so, see if the color is RED. If any of the cars have a color of RED, the fragment should be visible. Otherwise, it should be hidden.



The Javascript works fine when I preview the fragment in Designer using a sample XML input file with no color element (i.e. the text in the fragment is hidden).



The Javascript works fine in my main document (which has the fragment included in it) when in preview mode in Designer.



The Javascript does not work when I invoke my process in LiveCycle server. I pass in data that has 1 car without a color element, and for some reason my fragment is visible.



Is there something wrong with my Javascript? Is this the wrong way to check to see if an XML element is present? Is something else wrong?



Any help would be appreciated!



Thanks,

Andy

Replies

Highlighted

andygoldstein

19-11-2008

I guess a more appropriate question might be:<br /><br />How can I tell if my XML input data does or does not contain an element? Let's say I have<br /><br /><input><br /> <cars><br /> <car><br /> <make>VW</make><br /> </car><br /> </cars><br /></input><br /><br />How can I use Javascript to safely determine if the car has a <color> element?