[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript conditional processing If then else

Posted on 2010-09-24
3
Medium Priority
?
365 Views
Last Modified: 2012-05-10
Dear experts,

I  have the following code to draw a gantt chart and need to make certain milestones conditional. They should only be visible if the date values or not null.

I tried the following as you can see in my code but the code is false and not interpreted anymore. Can you pleas give me an example of how I can add new TaskItems conditionally?

I appreciate your help!

Many tahnsk,

skahlert2010
<script>
  var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'day');
  g.setShowRes(0); // Show/Hide Responsible (0/1)
  g.setShowDur(1); // Show/Hide Duration (0/1)
  g.setShowComp(1); // Show/Hide % Complete(0/1)
  g.setCaptionType('Caption');  // Set to Show Caption
  g.setShowStartDate(1); // Show/Hide Start Date(0/1)
  g.setShowEndDate(1); // Show/Hide End Date(0/1)
  g.setDateInputFormat('dd/mm/yyyy') 
  g.setDateDisplayFormat('dd/mm/yyyy') 

  if( g ) {
    if ($x('P1112_GP_AUFTAKT_START').value != null || $x('P1112_GP_AUFTAKT_END').value != null)
    {g.AddTaskItem(new JSGantt.TaskItem(1, 'Auftaktveranstaltung'    ,  $x('P1112_GP_AUFTAKT_START').value , $x('P1112_GP_AUFTAKT_END').value    ,  'fff600', '', 0, 'LWF',  100, 0, 0, 1));}
	end if};
	
	g.AddTaskItem(new JSGantt.TaskItem(2, 'Kartierung LRT Flachland', $x('P1112_KART_LRT_START').value  , $x('P1112_KART_LRT_END').value  ,  '00a3ff', '', 0, 'LWF',  20, 0, 0, 1, "1"));
	g.AddTaskItem(new JSGantt.TaskItem(3, 'Inventur LRT Flachland'  , $x('P1112_INV_LRT_START').value , $x('P1112_INV_LRT_END').value ,  'ff6347', '', 0, 'LWF',  30, 0, 0, 1, "1"));

    g.Draw();	
    g.DrawDependencies();


  }
  else
  {
    alert("not defined");
  }

</script>

Open in new window

0
Comment
Question by:skahlert2010
3 Comments
 
LVL 1

Accepted Solution

by:
boogiefromzk earned 2000 total points
ID: 33752168
try this:

<script>
  var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'day');
  g.setShowRes(0); // Show/Hide Responsible (0/1)
  g.setShowDur(1); // Show/Hide Duration (0/1)
  g.setShowComp(1); // Show/Hide % Complete(0/1)
  g.setCaptionType('Caption');  // Set to Show Caption
  g.setShowStartDate(1); // Show/Hide Start Date(0/1)
  g.setShowEndDate(1); // Show/Hide End Date(0/1)
  g.setDateInputFormat('dd/mm/yyyy') 
  g.setDateDisplayFormat('dd/mm/yyyy') 

  if( g ) {
    if ($x('P1112_GP_AUFTAKT_START').value != null || $x('P1112_GP_AUFTAKT_END').value != null)
    {g.AddTaskItem(new JSGantt.TaskItem(1, 'Auftaktveranstaltung'    ,  $x('P1112_GP_AUFTAKT_START').value , $x('P1112_GP_AUFTAKT_END').value    ,  'fff600', '', 0, 'LWF',  100, 0, 0, 1));}
	
	g.AddTaskItem(new JSGantt.TaskItem(2, 'Kartierung LRT Flachland', $x('P1112_KART_LRT_START').value  , $x('P1112_KART_LRT_END').value  ,  '00a3ff', '', 0, 'LWF',  20, 0, 0, 1, "1"));
	g.AddTaskItem(new JSGantt.TaskItem(3, 'Inventur LRT Flachland'  , $x('P1112_INV_LRT_START').value , $x('P1112_INV_LRT_END').value ,  'ff6347', '', 0, 'LWF',  30, 0, 0, 1, "1"));

    g.Draw();	
    g.DrawDependencies();


  }
  else
  {
    alert("not defined");
  }

</script>

Open in new window

0
 

Author Comment

by:skahlert2010
ID: 33752306
Hi boogiefromzk!

Thanks for your help! Well, I tried your code and the chart is displayed. However, even if 'P1112_GP_AUFTAKT_START' is null, the line gets displayed. It seems to me as if the value of  my element 'P1112_GP_AUFTAKT_START' is not fetched correctly.

Any other ideas?

Thank you!
0
 
LVL 3

Expert Comment

by:VeganBen
ID: 33760080
change line 13 to && instead of ||
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question