Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javavscript getElementById Conditions

Posted on 2009-05-07
5
Medium Priority
?
723 Views
Last Modified: 2013-12-07
Hi there
Using Oracle Application Express:
Have 4 items (4 select lists, with defaults '%')
Lists are grouped by 2 lists each e.g. project number (list1), then Order No for project (based on list1)
What I am trying to do:
select from the 2 lists, click on url link, opens another page.
for both groups of lists
does not meet the first condition...





--it works if i use individual codes for each conditions
--Html Header
<script language="JavaScript" type="text/javascript">
function callMyPopup (formItem1,formItem2) {
    var formVal1 = document.getElementById(formItem1).value;
    var formVal2 = document.getElementById(formItem2).value;
    var url;
  url = 'f?p=&APP_ID.:32:&APP_SESSION.::::P32_ARCHIVEPROJECT,P32_ARCHIVEPO:' + formVal1 + ',' + formVal2;
  w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
  if (w.opener == null)
  w.opener = self;
  w.focus();
  }
</script>
 
 
--Post Element Text - second list
<a href="javascript:callMyPopup(
'P19_ARCHIVEPROJECT',
'P19_ARCHIVEPO');">Preview Report</a>
---------------------------------------------------------------------------------------------------------------
--always goes to second condition--work in progress
 
<script language="JavaScript" type="text/javascript">
 
if (document.getElementById('P16_ARCHIVEPROJECT').value != '%') 
 
{
function callMyPopup (formItem1,formItem2) {
    var formVal1 = document.getElementById(formItem1).value;
    var formVal2 = document.getElementById(formItem2).value;
    var url;
  url = 'f?p=&APP_ID.:32:&APP_SESSION.::::P32_ARCHIVEPROJECT,P32_ARCHIVEPO:' + formVal1 + ',' + formVal2;
  w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
  if (w.opener == null)
  w.opener = self;
  w.focus();
  }
 
} 
else if (document.getElementById('P16_PROJECT').value != '%')
{
  function callMyPopup (formItem1) {
    var formVal1 = document.getElementById(formItem1).value;
    var url;
  url = 'f?p=&APP_ID.:16:&APP_SESSION.::::P16_PROJECT:' + formVal1;
  w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
  if (w.opener == null)
  w.opener = self;
  w.focus();
  }
}
else
  {
  document.write("<b>Hello World!</b>");
  }
 
</script>

Open in new window

0
Comment
Question by:ImraneA
[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
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 24326730
I'm not sure what you mean by this...

"for both groups of lists does not meet the first condition..."
0
 
LVL 10

Expert Comment

by:bugada
ID: 24326823
You'r using an odd syntax, you check the condition and defines a fucntion in both branch.
Try with a code refactorec like that
<script language="JavaScript" type="text/javascript">
function callMyPopup (formItem1,formItem2) {
   if (document.getElementById('P16_ARCHIVEPROJECT').value != '%') {
      var formVal1 = document.getElementById(formItem1).value;
      var formVal2 = document.getElementById(formItem2).value;
      var url = 'f?p=&APP_ID.:32:&APP_SESSION.::::P32_ARCHIVEPROJECT,P32_ARCHIVEPO:' + formVal1 + ',' + formVal2;
      var w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
      if (w.opener == null)
         w.opener = self;
      w.focus();
   } else if (document.getElementById('P16_PROJECT').value != '%') {
      var formVal1 = document.getElementById(formItem1).value;
      var url = 'f?p=&APP_ID.:16:&APP_SESSION.::::P16_PROJECT:' + formVal1;
      var w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
      if (w.opener == null)
         w.opener = self;
      w.focus();
   } else {
      document.write("<b>Hello World!</b>");
   }
}
</script>

Open in new window

0
 

Author Comment

by:ImraneA
ID: 24327732
Hi there
Thanks for comments:  Tried the code, does not work.  Generates errors.
Explain
group1
list1
list2 (filter based on list1) (popup page1) (you must select list1,2 to get popup page1)

group2
list3
list4 (filter based on list3) (popup page2) (you must select list3,4 to get popup page2)

see code ..






Cond
if i create a simple test, to test the condition for group 1, it works
--it works
<script language="JavaScript" type="text/javascript">
function test2()
{
if (document.getElementById('P19_ARCHIVEPROJECT').value == "%")
{
alert("yes " + document.getElementById('P19_ARCHIVEPROJECT').value); 
}
else if (document.getElementById('P19_ARCHIVEPROJECT').value !== "%")
{
alert("no " + document.getElementById('P19_ARCHIVEPROJECT').value); 
}
}
</script>
 
--take it to next stage, adding function popup, get errors
<script language="JavaScript" type="text/javascript">
function test2(formItem1,formItem2)
{
var formVal1 = document.getElementById(formItem1).value;
var formVal2 = document.getElementById(formItem2).value;
var url;
if (document.getElementById('P19_ARCHIVEPROJECT').value !== "%")
{
  function callMyPopup (formVal1,formVal2) 
 
{  
  url = 'f?p=&APP_ID.:32:&APP_SESSION.::::P32_ARCHIVEPROJECT,P32_ARCHIVEPO:' + formVal1  + ',' + formVal2 ;
  w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
  if (w.opener == null)
  w.opener = self;
  w.focus();
}
 
 
}
 
}
else if (document.getElementById('P19_ARCHIVEPROJECT').value == "%")
 
{
alert("no " + document.getElementById('P19_ARCHIVEPROJECT').value); 
}
}
</script>

Open in new window

0
 
LVL 10

Expert Comment

by:bugada
ID: 24327893
what error is displayed? Without your html is hard to do local tests.
0
 

Accepted Solution

by:
ImraneA earned 0 total points
ID: 24334744
Hi there

Solved the problem myself:
See code:

Thanks...
<script language="JavaScript" type="text/javascript">
function test2(formItem1,formItem2,formItem3) 
{
if (document.getElementById('P19_ARCHIVEPROJECT').value !== "%" & document.getElementById('P19_PROJECT_FROM').value == "%%")
{
var formVal1 = document.getElementById(formItem1).value;
var formVal2 = document.getElementById(formItem2).value;
var url;
  url = 'f?p=&APP_ID.:32:&APP_SESSION.::::P32_ARCHIVEPROJECT,P32_ARCHIVEPO:' + formVal1  + ',' + formVal2 ;
  w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
  if (w.opener == null)
  w.opener = self;
  w.focus();
}
else if (document.getElementById('P19_PROJECT_FROM').value !== "%%" & document.getElementById('P19_ARCHIVEPROJECT').value == "%")
{
  var formVal3 = document.getElementById(formItem3).value;
  var url2;
  url2 = 'f?p=&APP_ID.:16:&APP_SESSION.::::P16_PROJECT:' + formVal3;
  w = open(url2,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
  if (w.opener == null)
  w.opener = self;
  w.focus();
}
else
{
alert("else");
}
}
</script>

Open in new window

0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

670 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