GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   javascript... (https://gfy.com/showthread.php?t=667224)

STTBoss 10-17-2006 07:56 AM

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

fris 10-17-2006 07:57 AM

not sure about js, would be easy to do in php

mortenb 10-17-2006 08:16 AM

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

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

darksoul 10-17-2006 08:36 AM

Quote:

Originally Posted by Fris (Post 11094477)
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.

mortenb 10-17-2006 08:37 AM

Quote:

Originally Posted by darksoul (Post 11094698)
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 :pimp

darksoul 10-17-2006 08:38 AM

Quote:

Originally Posted by mortenb (Post 11094709)
you could ajax it and use both php and javascript :pimp

what does ajax has to do with php ?

psili 10-17-2006 08:52 AM

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>


STTBoss 10-17-2006 08:55 AM

Quote:

Originally Posted by mortenb (Post 11094574)
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

STTBoss 10-17-2006 08:56 AM

Quote:

Originally Posted by psili (Post 11094786)
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

mortenb 10-17-2006 08:58 AM

Quote:

Originally Posted by darksoul (Post 11094716)
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.

mortenb 10-17-2006 09:00 AM

Quote:

Originally Posted by STTBoss (Post 11094812)
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.


All times are GMT -7. The time now is 08:13 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123