Solved

Javascript conditional processing If then else

Posted on 2010-09-24
3
354 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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now