Page 2 of 2

Posted: Fri Jun 18, 2004 6:12 pm
by ol4pr0
I am afraid i lost u there..

Posted: Fri Jun 18, 2004 6:19 pm
by feyd
foo.html

Code: Select all

<html>
            <script language="Javascript">
            function getElem(id)
            {
              return document.getElementById?document.getElementById(id):document.allїid];
            }

            function updateForm(index)
            {
              var updArea = getElem('updArea');
              switch(index)
              {
               case 1:
                 updArea.innerHTML = '<br>Game Name:<input type="text" name="ps2" size="10"></input>';
                 break;
               case 2:
                 updArea.innerHTML = '<br>Game Name:<input type="text" name="xbox" size="10"></input>';
                 break;
               case 3:
                 updArea.innerHTML = '<br>Game Name:<input type="text" name="pc" size="10"></input>';
                 break;
               case 4:
                 updArea.innerHTML = '<br>Game Name:<input type="text" name="something" size="10"></input>';
                 break;

               default:
                 updArea.innerHTML = 'Please Select';
                 break;
              }
            }
            </script>
<body onload="document.formsї0].selectedIndex = 0;">
            <form action="foo.php" method="post">
            <select onchange="updateForm(this.selectedIndex)">
            <option>-select-</option>
            <option>ps2</option>
            <option>xbox</option>
            <option>pc</option>
            <!-- whatever else... -->
            </select><span id="updArea"></span><br>
            <INPUT TYPE="submit" name="submit" value="submit"></form>
</body>
</html>
foo.php

Code: Select all

<?php
header('Content-type: text/plain');

print_r($_POST);
?>
clicking submit with ps2 selected:

Code: Select all

Array
(
    &#1111;ps2] =&gt; feyd clicked submit
    &#1111;submit] =&gt; submit
)
hitting enter with xbox selected:

Code: Select all

Array
(
    &#1111;xbox] =&gt; feyd pressed enter
)

Posted: Fri Jun 18, 2004 6:26 pm
by ol4pr0
if i see this correctly the thing changed is

Code: Select all

onload="document.forms&#1111;0].selectedIndex = 0;"
I will try this.. thanks for the help

Posted: Fri Jun 18, 2004 6:51 pm
by feyd
that wasn't the real change.. that was a tweak to make it, on first load, say "Please Select"

the change that made it work:

Code: Select all

...name="ps2"...
...name="xbox"...
...name="pc"...
...name="something"...
originally you had

Code: Select all

...name"gname"...
...name"gname"...
...name"gname"...
...name"gname"...
(ignore the string changes, but the = sign is the important part.) Without the equal sign, there is nothing to pass, so posted data is empty.

Posted: Fri Jun 18, 2004 8:25 pm
by ol4pr0
thanks.. kinda stupid didnt notice the missing =