Jump to content

Recommended Posts

I am trying to show each checked item in a new row in an html (php) table.

Currently, it is working when one selection has been made via a checkbox, but when a new selection is made, the first one is overwritten.

 

I call my Checkboxes like this:

echo "<input type=\"checkbox\" rel=\"textbx1\" name=\"$item_no\">$item_no $ihddescr_1</input><br />";

Which gives me a list of items from a selected vendor.

 

I then use this table below, as I will need to show cost, price, etc in a table.

echo "<table border ='0' width='100%'><tr><td align='center'><strong><font size='4'><font color='#008301'>Quote Items</font></strong></td></tr></table>";
echo "<table border ='1' width='100%'>";
	
        echo "<th>Item ID</th>";
	echo "<th>Description</th>";
        echo "<th>QTY</th>";
	echo "<th>Sell Price</th>";
	echo "<th>Cost</th>";
        echo "<th>Prft%</th>";
        echo "<th>Prft$</th></tr>";			
				
	$quoted = "<td><text id=\"textbx1\"></text></td><td></td><td> </td><td> </td><td> </td><td><input type='text' name='profit' size='6'> </td><td> </td></tr>";
			
  	{
  	$cscode=odbc_result($rs,"cscode");
  	$csname=odbc_result($rs,"csname");
  	$item_no=odbc_result($rs,"item_no");
  	$order_date=odbc_result($rs,"order_date");					
  	$order_date2 = date( "m-d-Y", strtotime( $order_date ) );*/

  	$getQuote=array("$item_no \"\n\"");
  	foreach ($getQuote as $item)
  	$item = "$quoted";
{
echo $quoted;
}	
odbc_close($conn);
echo "</table>"; 

I should also add that I am using Javascript to populate the rows.

<script type="text/javascript">
$(window).load(function(){
    $(document).ready(function() {
$("input[type=checkbox]").click(function() {
    if ($(this).is(':checked'))
    $('#textbx1').html($('#textbx1').val() + $(this).attr('name') + "\n");
else
{
    var text = $('#textbx1').val();
    text = text.replace($(this).attr('name') + "\n" ,"");
    $('#textbx1').html(text);
}
  });
})
});
</script>

Any help what-so-ever would be appreciated.

 

Thanks.

Edited by FrankieGee

Sorry, I just copied your name= bit and didn't spot the $ in the name. Try

echo "<input type=\"checkbox\"  name=\"item_no[]\" value=\"$item_no\" />$item_no $ihddescr_1<br />";

Your selected item numbers will be in the array $_POST['item_no']

Hi Frank,

Taking a look at your file, couple suggestions that might help you debug (there's a few).  Enable Firebug on your Firefox browser, click the Consule tab and re-run your script.  You'll discover a few Javascript errors. For PHP you can setup an error log that will wright your custom errors out to a text file.  I like to do this wherever I'm trying to visualize whats going on under the hood.  The following code is how you would use this:

<?php
//log custom error messages
$log_path = "/path/to/your/log/file/dev_log_messages.txt";
$log_tstamp = date('Y-m-d G:H:s',time());

//then later in your code blocks
$someVariable = "Test String";
error_log($log_tstamp." the test string is ".$someVariable."\n",3,$log_path);

Using this technique will help you identify values or result that don't display to the browser window, but are critical to the process success.

 

Couple overall thoughts, ideally, you want your PHP code block above your HTML code block.  Specially since you are using sessions, the PHP session header needs sent before anything else.

<?php
session_start();
//some php code
?>
<html>
//some javascript and html
</html>

Sorry this doesn't answer your question directly, but in the long run, it will help you code better and faster.

Edited by rwhite35
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.