Solved

Am I asking the impossible?

Posted on 2004-09-13
18
294 Views
Last Modified: 2008-03-06
I have a script, very simple and sweet for option popup that lets me control the browser properties.

In the head I load:

<!--

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->

the drop down list in the body will look something like:

<form name="jump">
  <select name="menu" onChange="MM_openBrWindow(document.jump.menu.options[document.jump.menu.selectedIndex].value,'DaveysPlace','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=50,top=50,width=600,height=400')">
    <option>Select Location</option>
    <option value="http://www.cnn.com">CNN</option>
    <option value="http://www.yahoo.com">Yahoo</option>
    <option value="http://www.google.com">Google</option>
  </select>
</form>

The problem is nit picky but 2 fold.  First if the user makes a selection and then closes the window of thier selection, they cant chosse the same selection again without choosing another one first.

The second part is, if the choose the part that says choose location (which should just be for display) it causes a pop up window.  Idealy nothing should happen except for that text being displayed.

Any of you experts have any ideas?

~David
0
Comment
Question by:dtolo
  • 11
  • 7
18 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 12046078
To fix the first problem you would need to use a button. THat is just how the onchange event works. To cause that function to fire you would need to change hte select box. You could put a button next to the select box that when you click it it opens the window.


for the second problem you need an if statement in your functin, like this

function MM_openBrWindow( strLocation, strTitle, strProperties )
{
      // Do we open the window?
      if( strLocation != "" )
      {
            window.open( strLocation, strTitle, strProperties );
      }
}

that
0
 
LVL 2

Author Comment

by:dtolo
ID: 12046647
I am very new at this so please bear with me.  Are you saying that if I modify the part that sits in the head of the document to read:

<!--

function MM_openBrWindow(theURL,winName,features)
{
  if(theURL != "optionURL")
  {
  window.open(theURL,winName,features);
  }
}
that
//-->

It will cause whatever value I put in place of optionURL to not open?  
Can I put a few values in there, I use the script a few times on one page
And it would be helpful if I could put them all in.
0
 
LVL 2

Author Comment

by:dtolo
ID: 12046664
That is put all the ones I don't want to pop-up in at the same time.
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12046718
yeah, or you could do something like this ... which would probably be a bit more efficent


<html>
<body>
<script>      
function MM_openBrWindow( objTargetComboBox, strTitle, strProperties )
{

      // Do we open the window?
      if( objTargetComboBox.selectedIndex != 0 )
      {
            // YEs
            var strLocation = objTargetComboBox.options[ objTargetComboBox.selectedIndex ].value;
            window.open( strLocation, strTitle, strProperties );
      }
}
</script>
<form name="jump">
  <select name="menu" onChange="MM_openBrWindow(this ,'DaveysPlace','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=50,top=50,width=600,height=400')">
    <option>Select Location</option>
    <option value="http://www.cnn.com">CNN</option>
    <option value="http://www.yahoo.com">Yahoo</option>
    <option value="http://www.google.com">Google</option>
  </select>
</form>
</body>
</html>
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12046733
that will work as long as the Default Option ( in this case is "Select Location" ) is the first position

then you can use that function for as many combo boxes as needed
0
 
LVL 2

Author Comment

by:dtolo
ID: 12046825
OK'

I'll try it.

BRB

0
 
LVL 2

Author Comment

by:dtolo
ID: 12046869
I only know basic where if you use an if you have to use a then.
How does the if statement tell it not to open the window in this logic?
0
 
LVL 2

Author Comment

by:dtolo
ID: 12047049
OK,

I have this,

<script language="javascript">    
function MM_openBrWindow( objTargetComboBox, strTitle, strProperties )
{

     // Do we open the window?
     if( objTargetComboBox.selectedIndex != 0 )
     {
          // Yes
          var strLocation = objTargetComboBox.options[ objTargetComboBox.selectedIndex ].value;
          window.open( strLocation, strTitle, strProperties );
     }
}
</script>

When i try to use it I get the error:


Line: 66 char:11
Error: 'options' is null or not an object

Line 66 is:
  var strLocation = objTargetComboBox.options[ objTargetComboBox.selectedIndex ].value;
          window.open( strLocation, strTitle, strProperties );

0
 
LVL 2

Author Comment

by:dtolo
ID: 12047115
My combo boxes look like this:

<select size="1" name="IC" onChange="MM_openBrWindow(document.TA.IC.options[document.TA.IC.selectedIndex].value,'contacts','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=150,top=100,width=750,height=600')" style="width: 243; height: 19; border-style: groove; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; font-family:Arial; font-size:10pt" tabindex="3">
                                          <option selected>Instructors Corner</option>
                                          <option value="forms/AcademySignInSheets.pdf">Sign In Sheet</option>
                                          <option value="forms/Academyevaluationrev9-12-03.pdf">Course Evaluation</option>
                                          </select></td>

Where the form name is TA

So what do you think?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:dtolo
ID: 12047250
I changed it back to the way I originaly wrote it, but I kept your if statement,  I now have:

<script language="javascript">    
function MM_openBrWindow(theURL,winName,features)
{
     // Do we open the window?
     if(theURL.selectedIndex != 0)
     {
          // Yes
            window.open(theURL,winName,features);
     }
}
</script>

My pop ups work but the first selected option (in the case above "Instructors Corner") still causes a blank pop up.

What am I doing wrong?
0
 
LVL 2

Author Comment

by:dtolo
ID: 12047353
Even if I put the url in it still doesn't work

I have:

<script language="javascript">    
function MM_openBrWindow(theURL,winName,features)
{
     // Do we open the window?
     if(theURL != "Sign Up Page")

     {
          // Yes
            window.open(theURL,winName,features);
     }
}
</script>

It still creates a pop up for the selection "Sign Up Page"
0
 
LVL 2

Author Comment

by:dtolo
ID: 12047402
Anybody out there?
0
 
LVL 15

Accepted Solution

by:
justinbillig earned 500 total points
ID: 12047616
change this

<select size="1" name="IC" onChange="MM_openBrWindow(document.TA.IC.options[document.TA.IC.selectedIndex].value,'contacts','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=150,top=100,width=750,height=600')" style="width: 243; height: 19; border-style: groove; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; font-family:Arial; font-size:10pt" tabindex="3">
                                   <option selected>Instructors Corner</option>
                                   <option value="forms/AcademySignInSheets.pdf">Sign In Sheet</option>
                                   <option value="forms/Academyevaluationrev9-12-03.pdf">Course Evaluation</option>
                                   </select></td>


to this


<select size="1" name="IC" onChange="MM_openBrWindow(this ,'contacts','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=150,top=100,width=750,height=600')" style="width: 243; height: 19; border-style: groove; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; font-family:Arial; font-size:10pt" tabindex="3">
                                   <option selected>Instructors Corner</option>
                                   <option value="forms/AcademySignInSheets.pdf">Sign In Sheet</option>
                                   <option value="forms/Academyevaluationrev9-12-03.pdf">Course Evaluation</option>
                                   </select></td>


if you notice the onchange function i've change the first paramter to this ... that is a keyword for this object
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12047628
so hence




<html>
<body>
<script>    
function MM_openBrWindow( objTargetComboBox, strTitle, strProperties )
{

     // Do we open the window?
     if( objTargetComboBox.selectedIndex != 0 )
     {
          // YEs
          var strLocation = objTargetComboBox.options[ objTargetComboBox.selectedIndex ].value;
          window.open( strLocation, strTitle, strProperties );
     }
}
</script>
<form name="jump">
  <select name="menu" onChange="MM_openBrWindow(this ,'DaveysPlace','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=50,top=50,width=600,height=400')">
    <option>Select Location</option>
    <option value="http://www.cnn.com">CNN</option>
    <option value="http://www.yahoo.com">Yahoo</option>
    <option value="http://www.google.com">Google</option>
  </select>
</form>
</body>
</html>


the first parameter in the onchange function call is this
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12047670
when you pass it the object ( with the this keyword ) the if statment says .. if the selected index is not equal to zero ... meaning if the first object in the select box isnt selected, then open the window

MM_openBrWindow( objTargetComboBox, strTitle, strProperties )

in this case objTargetComboBox is like saying document.formname.controlname

so in the if statment we say if objTargetComboBox.selectedIndex != 0

which is also like saying ... if document.formname.controlname.selectedIndex != 0

the reason we pass the object reference to the combo box as a paramter is because you then could use it for any amount of combo boxes you want
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12047775
if your still a little confused a wrote a small page with a couple combo boxes on it to show the benefits of passing object references

<html>
<body>
<script>      
function MM_openBrWindow( objTargetComboBox, strTitle, strProperties )
{


      // Did the user choose the default option?
      if( objTargetComboBox.selectedIndex == 0 ) // Meaning the first option in the select box is chosen, remember it's zero based
      {
            // Yes, tell them they are going nowwhere
            alert( "You have selected the default option. No page will be opened" );
      }
      else
      {

            // Here we can tell which combobox you just changed
            alert( "You changed " + objTargetComboBox.name );

            // Here we can tell what the title is going to be
            alert( "The title of the page your going to open is " + strTitle )

            // HEre we can seet he window properties
            alert( "The window properties are " + strProperties )


            alert( "The url you are going to is " + objTargetComboBox.options[ objTargetComboBox.selectedIndex ].value );
      }
}
</script>
<form name="jump">
  <select name="ComboBox1" onChange="MM_openBrWindow(this ,'JustinsPlace','WindowProperties1')">
    <option>Select Location</option>
    <option value="http://www.url1.com">CNN</option>
    <option value="http://www.url2.com">Yahoo</option>
    <option value="http://www.url3.com">Google</option>
  </select>

  <select name="ComboBox2" onChange="MM_openBrWindow(this ,'DaveysPlace','WindowProperties2')">
    <option>Select Location</option>
    <option value="http://www.url4.com">CNN</option>
    <option value="http://www.url5.com">Yahoo</option>
    <option value="http://www.url6.com">Google</option>
  </select>



  <select name="ComboBox3" onChange="MM_openBrWindow(this ,'MikeysPlace','WindowProperties3')">
    <option>Select Location</option>
    <option value="http://www.url7.com">CNN</option>
    <option value="http://www.url8.com">Yahoo</option>
    <option value="http://www.url9.com">Google</option>
  </select>


  <select name="ComboBox4" onChange="MM_openBrWindow(this ,'HeathersPlace','WindowProperties4')">
    <option>Select Location</option>
    <option value="http://www.url10.com">CNN</option>
    <option value="http://www.url11.com">Yahoo</option>
    <option value="http://www.url12.com">Google</option>
  </select>
</form>
</body>
</html>
0
 
LVL 2

Author Comment

by:dtolo
ID: 12048035
Thank You!

So are you saying that I no longer need this part:

MM_openBrWindow(document.TA.IC.options[document.TA.IC.selectedIndex].

the document.TA.IC part calls the form and the combo box
0
 
LVL 2

Author Comment

by:dtolo
ID: 12048087
Thank You!  Love that Script!  Very Nice!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

705 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

13 Experts available now in Live!

Get 1:1 Help Now