javascript...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • STTBoss
    Confirmed User
    • Jun 2004
    • 225

    #1

    javascript...

    I have 2 select boxes. Now, how the hell do I change options in the second box when the first one is switched to another option by the user?!!! thanks
    TrafficAdept.com
    GET BETTER QUALITY TRAFFIC
    GET PAID MORE TO SELL TRAFFIC

    by DamageX and STTBoss
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55679

    #2
    not sure about js, would be easy to do in php
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

    Comment

    • mortenb
      Confirmed User
      • Jul 2004
      • 2203

      #3
      http://irt.org/script/form.htm#4

      irt.org is a nice site for stuff like this :-)

      Comment

      • darksoul
        Confirmed User
        • Apr 2002
        • 4997

        #4
        Originally posted by Fris
        not sure about js, would be easy to do in php

        with php it would happen on the server side (the user needs to submit)
        where with js it happens in the browser no submit needed.
        1337 5y54|)m1n: 157717888
        BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
        Cambooth

        Comment

        • mortenb
          Confirmed User
          • Jul 2004
          • 2203

          #5
          Originally posted by darksoul
          no it wouldn't.
          with php it would happen on the server side (the user needs to submit)
          where with js it happens in the browser no submit needed.
          you could ajax it and use both php and javascript

          Comment

          • darksoul
            Confirmed User
            • Apr 2002
            • 4997

            #6
            Originally posted by mortenb
            you could ajax it and use both php and javascript
            what does ajax has to do with php ?
            1337 5y54|)m1n: 157717888
            BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
            Cambooth

            Comment

            • psili
              Confirmed User
              • Apr 2003
              • 5526

              #7
              Not the greatest solution, but I was bored so, here it is:

              Code:
              <html>
               <head>
              <script type="text/javascript">
              
              // hook up your options
              slaveArr1 = new Array("Slave option 1","Slave option 2","Slave option 3");
              slaveArr2 = new Array("Another option 1","Another option 2","Another option 3");
              
              // do the work
              function updateSlave(val)
              {
              	var arr;
              	if(val != "") // test empty value
              	{
              		// set values
              		if(val == "1")
              			arr = slaveArr1;
              		else
              			arr = slaveArr2;
              
              		// reset slave
              		resetSlave();
              
              		// populate options
              		populateSlave(arr);
              
              	}
              }
              
              // populates select field
              function populateSlave(arr)
              {
              	for(i=0;i<arr.length;i++)
              	{
              		o = document.createElement("option");
              		o.setAttribute("value",arr[i]);
              		o.appendChild( document.createTextNode( arr[i] ) );
              		document.getElementById("slave").appendChild(o);
              	}
              }
              
              // kill options in slave select field
              function resetSlave()
              {
              	while(document.getElementById("slave").childNodes.length > 0)
              		document.getElementById("slave").removeChild( document.getElementById("slave").lastChild );
              }
               </script>
               </head>
               <body>
              
               <form method="GET" action="">
              	 <p>Select 1: 
              	   <select name="master" onchange="updateSlave(this.value)">
              		   <option value=""></option>
              		   <option value="1">Option 1</option>
              		   <option value="2">Option 2</option>
              	   </select>
              	 </p>
              
              	 <p>Select 2:
              		<select name="slave" id="slave"></select>
              
              	 </p>
              
               </form>
                 
              
               </body>
              </html>
              Your post count means nothing.

              Comment

              • STTBoss
                Confirmed User
                • Jun 2004
                • 225

                #8
                Originally posted by mortenb
                http://irt.org/script/form.htm#4

                irt.org is a nice site for stuff like this :-)
                thanks for the link, but it doesn't seem to work... I mean it does load, I click to faq #237 and then on the first link ( http://tech.irt.org/articles/js042/index.htm ) but it doesn't work. Does it open for anyone? If so, can someone copy it here? thanks
                TrafficAdept.com
                GET BETTER QUALITY TRAFFIC
                GET PAID MORE TO SELL TRAFFIC

                by DamageX and STTBoss

                Comment

                • STTBoss
                  Confirmed User
                  • Jun 2004
                  • 225

                  #9
                  Originally posted by psili
                  Not the greatest solution, but I was bored so, here it is:

                  Code:
                  <html>
                   <head>
                  <script type="text/javascript">
                  
                  // hook up your options
                  slaveArr1 = new Array("Slave option 1","Slave option 2","Slave option 3");
                  slaveArr2 = new Array("Another option 1","Another option 2","Another option 3");
                  
                  // do the work
                  function updateSlave(val)
                  {
                  	var arr;
                  	if(val != "") // test empty value
                  	{
                  		// set values
                  		if(val == "1")
                  			arr = slaveArr1;
                  		else
                  			arr = slaveArr2;
                  
                  		// reset slave
                  		resetSlave();
                  
                  		// populate options
                  		populateSlave(arr);
                  
                  	}
                  }
                  
                  // populates select field
                  function populateSlave(arr)
                  {
                  	for(i=0;i<arr.length;i++)
                  	{
                  		o = document.createElement("option");
                  		o.setAttribute("value",arr[i]);
                  		o.appendChild( document.createTextNode( arr[i] ) );
                  		document.getElementById("slave").appendChild(o);
                  	}
                  }
                  
                  // kill options in slave select field
                  function resetSlave()
                  {
                  	while(document.getElementById("slave").childNodes.length > 0)
                  		document.getElementById("slave").removeChild( document.getElementById("slave").lastChild );
                  }
                   </script>
                   </head>
                   <body>
                  
                   <form method="GET" action="">
                  	 <p>Select 1: 
                  	   <select name="master" onchange="updateSlave(this.value)">
                  		   <option value=""></option>
                  		   <option value="1">Option 1</option>
                  		   <option value="2">Option 2</option>
                  	   </select>
                  	 </p>
                  
                  	 <p>Select 2:
                  		<select name="slave" id="slave"></select>
                  
                  	 </p>
                  
                   </form>
                     
                  
                   </body>
                  </html>
                  thanks! I will test it out
                  TrafficAdept.com
                  GET BETTER QUALITY TRAFFIC
                  GET PAID MORE TO SELL TRAFFIC

                  by DamageX and STTBoss

                  Comment

                  • mortenb
                    Confirmed User
                    • Jul 2004
                    • 2203

                    #10
                    Originally posted by darksoul
                    what does ajax has to do with php ?
                    nothing as such.. ajax is just a name for using different technologies together.. php can be a part of ajax if you choose so.

                    Comment

                    • mortenb
                      Confirmed User
                      • Jul 2004
                      • 2203

                      #11
                      Originally posted by STTBoss
                      thanks for the link, but it doesn't seem to work... I mean it does load, I click to faq #237 and then on the first link ( http://tech.irt.org/articles/js042/index.htm ) but it doesn't work. Does it open for anyone? If so, can someone copy it here? thanks
                      Try 1046.. Play around with it a bit.. It's not as difficult as it seems.

                      Comment

                      Working...