OnChange="submit();" with submit buttons on form a

  • SOTY2004
  • Student
  • Student
  • User avatar
  • Joined: Jun 10, 2005
  • Posts: 90
  • Loc: Ontario, Canada
  • Status: Offline

Post February 4th, 2006, 5:38 pm

Another brain buster guys (to me this is nuts)

I have a submit button on my form, but i also have a drop down box that needs to change items in some textboxes. here's what i have as code, maybe it would be better if you saw what i was doing.

Code: [ Download ] [ Select ]
<form method=post action="index.php?section=editcourse" name='edit'>
    <table border=0 cellspacing=0 cellpadding=0>
        <tr>
            <td align=center>
                Edit a Course<p>
            </td>
        </tr>
        <tr>
            <td align=left>
                <select name='courses' onChange="edit.submit;">
                    <optgroup label="Courses">
                <?php
                $connect->Connected();
                mysql_select_db('db_courses');
                $result = $connect->query('Select * from tblcourses');
                while ($row = $connect->fetchArray($result))
                {
                    echo "<option value='".$row['CourseID']."'>".$row['CourseCode']."</option>";
                }
                ?>
                $connect->close();
                    </optgroup>
                </select><p>
            </td>
        </tr>
        <tr>
            <td>
                Course Code:&nbsp;<input type=text name=coursecode maxlength=10 value=<?php ?>><p>
            </td>
        </tr>
        <tr>
            <td>
                Course Name:<input type=text name=coursename maxlength=50><p>
            </td>
        </tr>
        <tr>
            <td colspan=2 align=center>
                <input type=submit value="Submit" name=submit>
                <input type=reset value="Reset" name=reset>
            </td>
        </tr>
    </table>
</form>
  1. <form method=post action="index.php?section=editcourse" name='edit'>
  2.     <table border=0 cellspacing=0 cellpadding=0>
  3.         <tr>
  4.             <td align=center>
  5.                 Edit a Course<p>
  6.             </td>
  7.         </tr>
  8.         <tr>
  9.             <td align=left>
  10.                 <select name='courses' onChange="edit.submit;">
  11.                     <optgroup label="Courses">
  12.                 <?php
  13.                 $connect->Connected();
  14.                 mysql_select_db('db_courses');
  15.                 $result = $connect->query('Select * from tblcourses');
  16.                 while ($row = $connect->fetchArray($result))
  17.                 {
  18.                     echo "<option value='".$row['CourseID']."'>".$row['CourseCode']."</option>";
  19.                 }
  20.                 ?>
  21.                 $connect->close();
  22.                     </optgroup>
  23.                 </select><p>
  24.             </td>
  25.         </tr>
  26.         <tr>
  27.             <td>
  28.                 Course Code:&nbsp;<input type=text name=coursecode maxlength=10 value=<?php ?>><p>
  29.             </td>
  30.         </tr>
  31.         <tr>
  32.             <td>
  33.                 Course Name:<input type=text name=coursename maxlength=50><p>
  34.             </td>
  35.         </tr>
  36.         <tr>
  37.             <td colspan=2 align=center>
  38.                 <input type=submit value="Submit" name=submit>
  39.                 <input type=reset value="Reset" name=reset>
  40.             </td>
  41.         </tr>
  42.     </table>
  43. </form>


if any of you have an idea what the hell i'm talking about. Your help will be quite appreciated.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 4th, 2006, 5:38 pm

  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11872
  • Loc: Clearwater, FL
  • Status: Offline

Post February 4th, 2006, 6:03 pm

This ?
Code: [ Download ] [ Select ]
onChange="this.form.submit();"
Why yes, yes I am.
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Joined: Jun 10, 2005
  • Posts: 90
  • Loc: Ontario, Canada
  • Status: Offline

Post February 4th, 2006, 6:23 pm

No go. that didn't work. That looked to me that it would work :(
  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11872
  • Loc: Clearwater, FL
  • Status: Offline

Post February 4th, 2006, 6:48 pm

Ok.
What should happen after someone does what ?
What should be doing the what that happens ?
Why yes, yes I am.
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Joined: Jun 10, 2005
  • Posts: 90
  • Loc: Ontario, Canada
  • Status: Offline

Post February 4th, 2006, 10:45 pm

Alright, here's my situation to make things clear :D

In the editing section of my PHP script, the user will be able to select from a drop down list of what they want to edit, once they select what they want, the value of the drop down list will be the ID that will relate to a table in a MySQL database. On that change to the course that the user desiers, this will in turn fill 2 text boxes, the course code, and its description.

But this can only happen, in my opinion during a submit. If you have another way, i'm willing to try anything.

Hope that is clear enough :?
  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11872
  • Loc: Clearwater, FL
  • Status: Offline

Post February 4th, 2006, 11:02 pm

Code: [ Download ] [ Select ]
echo "<option value='".$row['CourseID']."'>".$row['CourseCode']."</option>";


I get the feeling 'CourseID' is an integer identifier of the course.
What would 'CourseCode' be ?

Are both of thoose values the ones that would fill the textboxes ? Or does a trip to the server need to be made to get the 'Course Name' ?
Why yes, yes I am.
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Joined: Jun 10, 2005
  • Posts: 90
  • Loc: Ontario, Canada
  • Status: Offline

Post February 4th, 2006, 11:13 pm

CourseCode is a string that is 10 char long....

I have the coursecode displaying in the drop down list, and tested to see if the id was set properly (go javascripts alert :D)

I just need it to, onChange, change accordingly, keep in mind, that i have a submit button. When I remove it, it works...so i don't know anymore :(
  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11872
  • Loc: Clearwater, FL
  • Status: Offline

Post February 5th, 2006, 1:42 am

You remove the submit button & it works ? :eek6:

Try replacing that submit button with a normal button that has a submit attached ?
Code: [ Download ] [ Select ]
<input type="button" value="Submit" name="submit" onclick="this.form.submit();">


I'm pretty confused at this point.
Why yes, yes I am.
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Joined: Jun 10, 2005
  • Posts: 90
  • Loc: Ontario, Canada
  • Status: Offline

Post February 5th, 2006, 11:08 am

what i ended up doing is get rid of the submit button, and when the onchange happened, i had it go to a different page, passing the value.

Appreciate the help joebert, you help didn't go in vain.
  • staccatoTaco
  • Born
  • Born
  • No Avatar
  • Joined: Jul 01, 2009
  • Posts: 1
  • Status: Offline

Post July 1st, 2009, 3:31 pm

I think what's happening here is that the name of the Submit element is overriding the submit() form function. By renaming the Submit element, I was able to get both the onChange and Submit button submissions to work.

Code: [ Download ] [ Select ]
<input type="button" value="Submit" name="submitForm" onclick="this.form.submit();">
  • UPSGuy
  • Lurker ಠ_ಠ
  • Mastermind
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2497
  • Loc: Nashville, TN
  • Status: Offline

Post July 1st, 2009, 3:33 pm

staccatoTaco - take note of the last reply prior to yours. You responded to a 3 year old thread. If you'd like to participate in more current threads, visit us here.
I'd love to change the world, but they won't give me the source code.

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 139 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.