Jump to content

Help with this selectbox code


eits

Recommended Posts

Hi everybody!

 

I have the following code which I am using to get customer names from a database. I have the dropdown on a form but when I click submit I have to press it twice as the first time I do it all the data seems to go from the page. Is there anything strange any of you can see here as when I remove it I do not have to press submit twice. (Doesnt help when I remove JS onchange event either - definitely not this)

 

Thanks

<select name="clientdd" id="clientdd" onChange="formHandler()">
      <?php do { ?>
      
  <option value="<?php echo $row_custdb['clientname']?>" selected=""> 
  <?php echo $row_custdb['clientname']?>	  </option>
  	  
      <?php
} while ($row_custdb = mysql_fetch_assoc($custdb));
  $rows = mysql_num_rows($custdb);
  if($rows < 10) {
      mysql_data_seek($custdb, 0);
  $row_custdb = mysql_fetch_assoc($custdb);
  }
?>
      </select>

Link to comment
Share on other sites

Form Code:

<form id="form1" name="form1" method="post" action="<?php echo $editFormAction; ?>">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td width="118">Client Name </td>
      <td width="168"> 
  
  <select name="clientdd" id="clientdd" onChange="formHandler()">
      <?php do { ?>
      
  <option value="<?php echo $row_custdb['clientname']?>" selected=""> 
  <?php echo $row_custdb['clientname']?>	  </option>
  	  
      <?php
} while ($row_custdb = mysql_fetch_assoc($custdb));
  $rows = mysql_num_rows($custdb);
  if($rows < 10) {
      mysql_data_seek($custdb, 0);
  $row_custdb = mysql_fetch_assoc($custdb);
  }
?>
      </select></td>
    </tr>
    <tr>
      <td>Job Number </td>
      <td><label>
     <select name="jobnumdd" id="jobnumdd">
           <?php do { ?>
           <option value="<?php echo $row_jobdb['jobnumber']?>" selected="<?php $row_jobdb['jobnumber'] ?>"> <?php echo $row_jobdb['jobnumber']?></option>
           <?php
} while ($row_jobdb = mysql_fetch_assoc($jobdb));
  $rows = mysql_num_rows($jobdb);
  if($rows < 10) {
      mysql_data_seek($jobdb, 0);
  $row_jobdb = mysql_fetch_assoc($jobdb);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td>Hours Worked </td>
      <td><label>
        <input name="flhourstoday" type="text" id="flhourstoday" value="0:00" />
      </label></td>
    </tr>
    <tr>
      <td>Remaining Hours</td>
      <td><label>
        <input name="flremhours" type="text" id="flremhours" value="<?php echo $hoursremaining; ?>">
      </label></td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <input type="submit" name="Submit" value="Submit" />
      </label></td>
    </tr>
  </table>
  <p>


    <input type="hidden" name="clientid" value="<?php echo $row_custdb['clientid']; ?>" />
    <input type="hidden" name="clientname" value="<?php echo $_POST['clientdd']; ?>" />
    <input type="hidden" name="hoursleft" value="<?php echo $row_custdb['hoursleft']; ?>" />
    <input type="hidden" name="hoursallocated" value="<?php echo $row_custdb['hoursallocated']; ?>" />
    <input type="hidden" name="hoursworked" value="<?php echo $row_custdb['hoursworked'] + hourstodecimal($_POST['flhourstoday']); ?>" />
    <input type="hidden" name="jobid" value="<?php echo $row_jobdb['jobid']; ?>" />
    <input name="jobnumber" type="hidden" id="jobnumber" value="<?php echo $_POST['jobnumdd']; ?>" />
    <input name="timeonjob" type="hidden" id="timeonjob" value="<?php echo $row_jobdb['timeonjob'] + $_POST['flhourstoday']; ?>" />
  </p>
</form>

 

More Code:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tblcustomer SET clientname=%s, hoursworked=%s, hoursleft=%s, hoursallocated=%s WHERE clientid=%s",
                       GetSQLValueString($_POST['clientname'], "text"),
                       GetSQLValueString($_POST['hoursworked'], "text"),
                       GetSQLValueString($_POST['hoursleft'], "text"),
                       GetSQLValueString($_POST['hoursallocated'], "text"),
                       GetSQLValueString($_POST['clientid'], "int"));

  mysql_select_db($database_timedb, $timedb);
  $Result1 = mysql_query($updateSQL, $timedb) or die(mysql_error());
  print 'Query Ran: '.$updateSQL.' Result: '.$Result1;
}

 

::) ::)::)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.