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

  • SOTY2004
  • Student
  • Student
  • User avatar
  • Posts: 90
  • Loc: Ontario, Canada

Post 3+ Months Ago

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: [ 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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

This ?
Code: [ Select ]
onChange="this.form.submit();"
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Posts: 90
  • Loc: Ontario, Canada

Post 3+ Months Ago

No go. that didn't work. That looked to me that it would work :(
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Ok.
What should happen after someone does what ?
What should be doing the what that happens ?
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Posts: 90
  • Loc: Ontario, Canada

Post 3+ Months Ago

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
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Code: [ 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' ?
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Posts: 90
  • Loc: Ontario, Canada

Post 3+ Months Ago

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
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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

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


I'm pretty confused at this point.
  • SOTY2004
  • Student
  • Student
  • User avatar
  • Posts: 90
  • Loc: Ontario, Canada

Post 3+ Months Ago

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
  • staccatoTaco
  • Posts: 1

Post 3+ Months Ago

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: [ Select ]
<input type="button" value="Submit" name="submitForm" onclick="this.form.submit();">
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

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.

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 88 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.