Page 1 of 1

Select box selecting

Posted: Tue Jun 13, 2006 6:13 am
by tommy1987
Hi, I have the following code, what I want to do is submit that form when an option is selected, is there some way I can do this?
My reasoning for this is that I wish to populate another select box depending on what this one is.

Code: Select all

<?php
     //Code to display the region select box from the DB
     include("include-mysql.php"); 
     $query = "SELECT regionName from Region ORDER BY regionName ASC";
     $result = mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
     $i = 0;
     
     echo '<form name="RegSel" method="get" action="register.php"><select name="Region">';
      
   while ($row = mysql_fetch_array($result)) {
          echo '<option value="'.$row['regionName'].'">'.$row['regionName'].'</option>';
          $i++;
}
  ?>
Thanks very much.. Tom

Posted: Tue Jun 13, 2006 6:25 am
by JayBird
Moved to Client Side

Posted: Tue Jun 13, 2006 7:01 am
by jayshields
Change your select tag to something like this:

Code: Select all

<select name="blah" onChange="myform.submit();">

Posted: Tue Jun 13, 2006 8:01 am
by tommy1987
Here is my code, it still doesn't work though, the form just will not submit at all!

Code: Select all

<?php
//Code to display the region select box from the DB
    include("include-mysql.php"); 
    $query = "SELECT regionName from Region ORDER BY regionName ASC";
    $result = mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
    $i = 0; ?>
    <form name="myform1" method="get" action="register.php"><select onChange="myform1.submit();" name="Region"> <?php
    while ($row = mysql_fetch_array($result)) {
        echo '<option value="'.$row['regionName'].'">'.$row['regionName'].'</option>';
        $i++;
       }
    echo '</select></form>';
?>
Anyone any ideas??

Thanks, Tom

Posted: Tue Jun 13, 2006 9:52 am
by pickle
Are you testing this in Firefox? What Javascript errors (if any) are you getting?

Posted: Tue Jun 13, 2006 9:55 am
by tommy1987
it is saying 'myform1' is undefined which we all know is not true!

Im testing in IE but have tried in firefox too of which neither work..

Thanks..

Posted: Tue Jun 13, 2006 10:00 am
by pickle
Maybe try

Code: Select all

document.getElementById('myform1').submit()
rather that

Code: Select all

myform1.submit()

Posted: Tue Jun 13, 2006 10:36 am
by tommy1987
Having done that, I am now getting the following error:

Error: 'document.getElementById[...]' is null or not an object

Its driving me mad!!

Hope someone knows what the problem is, never had any problems with doing this kind of thing before!!

-Tom

Posted: Tue Jun 13, 2006 10:39 am
by feyd
how about

Code: Select all

this.form.submit();
I hope you don't have another field (or button) named submit though.

Posted: Tue Jun 13, 2006 10:40 am
by JayBird
Add the id to your form tag

Code: Select all

<form name="myform1" id="myform1" method="get" action="register.php">

Posted: Tue Jun 13, 2006 10:55 am
by tommy1987
Thanks very much got it working with this.form.submit().