Jump to content

[SOLVED] PHP and JavaScript - Using a Select All


JJ123

Recommended Posts

I know that PHP is server side and JavaScript is client side. So I need guidance on how to get the logic working in my code. The user searches for records based on a date range. Then with the results, the users can click on a link to 'select all' and all the checkboxes on the page are filled. I then want the user to be able to enter a box number and click on a save button and I want this to save the box number to each record. I have a save button that calls a Javascript that confirms that there is at least one checkbox checked, otherwise an error is thrown.

 

I was hoping to put the PHP code in there that updates the record with the box number. But this is not possible right? What would be the best way to go about this?

 

Thank you.

 

Below is my code:

 

Below is my code so far:

 

...

 

?>

<script language = "Javascript">

<!--

 

var form='filing'

 

function SetChecked(val,chkName)

{

    dml=document.forms[form];

    len = dml.elements.length;

    var i=0;

    for( i=0 ; i<len ; i++)

    {

          if (dml.elements.name==chkName)

          {

              dml.elements.checked=val;

          }

    }

}

 

function ValidateForm(dml,chkName)

{

    len = dml.elements.length;

    //alert(len);

    var i=0;

    for( i=0 ; i<len ; i++)

    {

          if ((dml.elements.name==chkName) && (dml.elements.checked==1))

          {

              alert(dml.elements.value);

              var flag = 1;

          }

    }

    if(flag == '1')

    {

          return true;

    }

    else

    {

          alert("Please select at least one record to be added to the box number.")

          return false;

    }

}

// -->

</script>

 

<?php

$start = $_REQUEST['start_date'];

$end = $_REQUEST['end_date'];

 

if($start == $end)

{$query = "SELECT * FROM tblshiplog Where date LIKE '$start%'";}

 

$result = mysql_query($query) or die(mysql_error());

$myrows = mysql_num_rows( $result );

   

    if ($myrows == 0)

    {echo "<br><center><b>Sorry, no records were found!</b></center>";}

    else

    {   

          print "There are $myrows records that match the criteria.<br><br>";

          ?>

          <form action='' method='post' name='filing' onSubmit="return ValidateForm(this,'chk')">

                <div align="center">

          <table cellspacing='3' cellpadding='3'>

          <tr>

                <td><input type='submit' name='save' value='Save'></td>

                <td><a href="javascript:SetChecked(1,'chk')"><font face="Arial, Helvetica, sans-serif" size="2">

          Check All</font></a>  </td>

          <td><a href="javascript:SetChecked(0,'chk')"><font face="Arial, Helvetica, sans-serif" size="2">

          Clear All</font></a></td></tr></table></div><br>

 

          Box Number: <input type='text' name='box'><br>

          <input type='hidden' name='start_date' value='<?php echo $start ?>'>

          <input type='hidden' name='end_date' value='<?php echo $end ?>'>

 

          <?php

          ?><table border=1>

          <tr><td></td><td><b><center>LID or Audit Number</td>   

          <td><b><center>BaaN Number</td><td><b><center>Date</td></tr><?PHP

 

             

              for ($i = 0; $i < mysql_num_rows( $result ); ++$i)

              {

                    $line = mysql_fetch_array($result);

                    ?>

                    <tr>

                    <td><input type='checkbox' name='chk' value='<?php echo $line['id'] ?>'></td>

                    <?php

                    if($line['lob'] == 'SPO')

                    {

                        ?>                       

                        <td><?PHP echo $line['audit']." (audit #)" ?></td>

                        <td>N/A</td>

                        <?PHP

                    }

                    else

                    {

                        ?>

                        <td><?PHP echo $line['lid'] ?></td>

                        <td><?PHP echo $line['baan'] ?></td>

                        <?PHP

                    }

                    ?>

                    <td><?PHP echo $line['date'] ?></td>

                    <td><input type=text name="id" value="<?PHP echo $line['id'] ?>"></td>

                    </tr>

                    <?php

              }

              ?></form></table><?PHP         

    }

...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.