Link to home
Start Free TrialLog in
Avatar of dtolo
dtolo

asked on

Am I asking the impossible?

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
Avatar of justinbillig
justinbillig

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
Avatar of dtolo

ASKER

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.
Avatar of dtolo

ASKER

That is put all the ones I don't want to pop-up in at the same time.
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>
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
Avatar of dtolo

ASKER

OK'

I'll try it.

BRB

Avatar of dtolo

ASKER

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?
Avatar of dtolo

ASKER

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 );

Avatar of dtolo

ASKER

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?
Avatar of dtolo

ASKER

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?
Avatar of dtolo

ASKER

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"
Avatar of dtolo

ASKER

Anybody out there?
ASKER CERTIFIED SOLUTION
Avatar of justinbillig
justinbillig

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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>
Avatar of dtolo

ASKER

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
Avatar of dtolo

ASKER

Thank You!  Love that Script!  Very Nice!