Solved

Javascript conditional processing If then else

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

863 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

18 Experts available now in Live!

Get 1:1 Help Now