Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2007
    Posts
    26

    Unanswered: can't submit the form

    hi..
    i'm using js to submit the form that i have,
    my php code is
    Code:
    for($i=0; $i<$period; $i++)
                             {
                                  print "<form name= \"bookAppointment$i\" id= \"bookAppointment\" action= \"../action/bookAppointment.php\" method= \"GET\">";
                                  print "<tr>";     
                                  print "<td class= \"textCenter\">";
                                  print $time;
                                  print "</td>";
                                  $query_view_appointment= "select a.appId, a.timeFrom, s.sname, p.pname, ata.appTypeName, asa.appStatName";
                                  $query_view_appointment2 =" where a.staffId='$staffId' and a.staffId=s.staffId and a.date= '$date' and a.timeFrom ='$time' and a.patientId=p.patientId and a.appStatId=asa.appStatId and a.appTypeId=ata.appTypeId";
                                  $query_view_appointment.= $query_view_appointment1.$query_view_appointment2;
                                   $result= safe_query($query_view_appointment);
                        
                                  while (list($appId, $timeFrom, $sname, $pname, $appTypeName, $appStatName)= mysql_fetch_array($result))
                                  {
                                     
                                      print "<td class= \"textCenter\">";
                                    ?>
                                        <a href= "staff.php?staffId=<?php echo $sname?>"><?php echo $sname ?></a>
                                    <?php
                                      print "</td>";
                                      print "<td class= \"textCenter\">";
                                    ?>
                                            <a href= "patient.php?patientId=<?php echo $patientId?>"><?php echo $pname ?></a>
                                    <?php
                                      print "</td>";
                                      print "<td class= \"textCenter\">";
                                      print $appTypeName;
                                      print "</td>";
                                      print "<td class= \"textCenter\">";
                                      print "<select name= \"appStatName\" class= \"textBox\">";
                                      $result_app_stat = safe_query("SELECT appStatName FROM appointment_status");
                              
                                              while (list($appStatName1)= mysql_fetch_array($result_app_stat))
                                           {
                                           print "<option name= \"$appStatName1\" value= \"$appStatName1\">$appStatName1</option>";
                                       
                                        }
                                      print "</select>";
                                      print "</td>";
                                      print "<td class= \"textCenter\">";
                                      print "<input type= \"hidden\" name= \"staffId\" value= \"$staffId\">";
                                      print "<input type= \"hidden\" name= \"patientId\" value= \"$patientId\">";
                                      print "<input type= \"hidden\" name= \"date\" value= \"$date\">";
                                      print "<input type= \"hidden\" name= \"time\" value= \"$time\">";
                                      print "<input type= \"hidden\" name= \"page\" value= \"changeStatus\">";
                                      print "<a href= \"javascript: submitForm()\"> Change </a> ";
                                      print "</td>";
                                  }   
                                   print "</tr>";
                                    print "</form>";
                            }
    i don't know what's wrong with this code, but the javascript doesn't work..
    this is my js code:
    Code:
    function submitForm()
    {
        document.getElementbyID("form").submit();
    }
    can anyone help me with this?
    thank's alot for your attention..

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    It seems fairly obvious that you haven't given your submitForm function the ID of the form. You've given it the string "form" but that does not correspond to an ID of any elements in the DOM. You might want to try giving it the right ID

    Code:
    function submitForm() {
        document.getElementbyID("bookAppointment").submit();
    }

  3. #3
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Looking at your code a little further it seems that you are creating a form element up to $period times. Thus giving yourself (if period is 3)
    Code:
    <form name= "bookAppointment0" id="bookAppointment">
      ...
    </form>
    <form name= "bookAppointment1" id="bookAppointment">
      ...
    </form>
    <form name= "bookAppointment2" id="bookAppointment">
      ...
    </form>
    Question : now when someone submits the form using the submitForm() javascript function which DOM element is it going to use (and thus submit), seeing as all three of the ones above have the same ID...

    Might be worth rethinking where your loop works, or alternatively if you don't want to put the loop inside the form element (i've just given you a hint there) consider how you might tell the submitForm function which DOM object it's submitting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •