[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Javascript conditional processing If then else

Posted on 2010-09-24
3
Medium Priority
?
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

656 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