Jump to content

Recommended Posts

In my first dropdown box I want to have these two(maybe more later) words.

 

OZ Functions

Scripting Basics

 

Now if the first dropdown box selects OZ Functions then I need it to use this array for the second dropdown box

$t = array("???","general","entity","animation","counter","core","float","enhanced");

 

If the first dropdown box selects Scripting Basics I then need it to show this array for the second dropdown box

$t = array("???","Basic Logical Operators","Basic Relational Operators","Basic keywords","Integer numeric constants","Predefined constants","Predefined tag names","Character constants");

 

The size of the array may change, but can you help get me started by telling it what to show in the second drop down box?

I plan on using the values 0 - 7 for the first array and 20 - 27 for the second. I'm using a big gap incase if I add more commands so I don't have to edit the mysql table fields.

Link to comment
https://forums.phpfreaks.com/topic/227581-change-second-dropdown/
Share on other sites

try something like this:

 

  • use a different variable name for each of the arrays for the second select list (arrayA and arrayB?) and build each array (then you can change/add to each later as necessary without changing the rest of the code)
     
  • Get the value of select1
  • start a new string variable and use it to start the 2nd select, such as:

  var select2 = "<select id='select2'>";

  • run if/else statement like if select1.value is OZ

In the if/else:

[*]step through arrayA and append each item as an <option> to select2

[*]in the else, step through arrayB and append each item as an option to select2

After the if/else

  • close out select2: select2 +="</select>"
  • attach select2 to the dom in the appropriate location/div

In your document load/ready section:

  • attach the onchange event handler to call the new function.

 

Doing it this way will essentially create the 2nd option list on the fly when something is selected off the first list.  If you want the list to appear already, just include it in the html and remove the steps where you start/end select2 with <select>and </select>; just build the <option>'s and add them in.  This will require a little bit more finnesse with your element selectors to get it in the right spot (or you can include <select>&</select> and just replace the ones in the existing html).

 

jQuery would make this easier, btw, because it's selector is so powerful. 

 

 

lol...I think you mean javascript, not java.  2 entirely different animals ;)

 

if you're trying to learn javascript to do this project, I suggest you learn jQuery first--it's a javascript framework that DRAMATICALLY eases the learning curve for javascript and eliminates most of the cross-browser issues that you have to work around in javascript.  What can take you many lines in javascript you can do in just a few lines using jQuery.

 

No one around here is  going to write your code for you, but we'll write short snippets or offer an example.  If we write the code for you, you won't learn.  I've written everything for you in psuedocode, now you just need to learn jQuery and put it together.

 

I HIGHLY recommend the book jQuery: Novice to Ninja.  I've been through a bunch of books recently to learn javascript/jQuery, and this one is by far the best one.  Rather than just throw some random projects at you, it walks you through building an actual jQuery project -a robust website--with a consistent context from beginning to end. 

Sorry I don't read books. I get bored too easily.

So far I learned html, php, mysql, just a dash of c++.

How did I learn this... by copying and pasting different scripts and then memorizing them.

 

So if I get different versions of this script, I got a higher chance of learning it.

I found what I needed online but it's not 100% correct.

 

<script>
function loadTypes()
{
   var ozfun=new Array("???","general","entity","animation","counter","core","float","enhanced");
   var ozbac=new Array("???","Basic Logical Operators","Basic Relational Operators","Basic keywords","Integer numeric constants","Predefined constants","Predefined tag names","Character constants","Misc","Advanced");

   var selectedBoxValue=document.functions.inc1.value;
   var i;
   var j;

   var inc2Length=eval(selectedBoxValue).length;

   removeSelectboxOption();

   for(i=0;i<document.functions.inc1.options.length;i++)
   {
    if(selectedBoxValue==document.functions.inc1.options[i].value)
    {
      for(j=0;j<inc2Length;j++)
      {
        document.functions.inc2.options[j]=new Option(eval(selectedBoxValue)[j],eval(selectedBoxValue)[j])
      }
    }
   }
}

function removeSelectboxOption()
{
   var i;
   for(i=0;i<document.functions.inc2.options.length;i++)
   {
    document.functions.inc2.remove(i);
   }
}
</script>

I just need the value of the box to be 0 - 7 for the second box if you choose ozfun for the first box.

Or 10 - 19 for the second box if you choose ozbac for the first box.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.