Please excuse me if this question is elementary - fairly new to working with mysql. I left out the query and loop/references in the code below, because my question is on formatting the table. (I hope that info isn't needed)
Right now the result of the code below is the info being displayed in one single table row that spans the width of the table, these rows continue until all data is displayed.
How can I format this so instead of one long cell in one table row, I get two cells per table row?
I haven't been able to figure out if this is a matter of formatting the table into 2 columns or formatting the tr or td.
Thank you very much for your help and guidance on this!!
echo('<table width="85%" align="center" cellspacing="15">');
//query,loop, references
echo('<tr>
<td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px">
<div style="float:right">
<form action="index.php" method="get">
<input type="hidden" name="page" value="viewproject">
<input type="hidden" name="projectid" value="'.$projectid.'">
<input type="submit" value="View Event"></form>
<br>
<form action="jump_delete.php" method="post" align="right">
<input type="hidden" name="projectid" value="'.$projectid.'">
<input type="submit" value="Delete"></form>
</div>
<div style="font-weight:bold; font-size:18px">'.$projectclient.'</div>
<div style="font-size:15px"><b>Event:</b> '.$projectname.'</div>
<div style="font-size:15px">Date: '.$duedateformatted.'</div>
<div style="font-size:15px">Staff Count: '.$projectstaffcount.'</div>
</td>
</tr>');
UPDATE: With using my own version of the help from below - I came to an answer that gets the job done for me. Thanks to all who chimed in with help and advice!!! Using an if statement to create when new rows happen.
if($i % 2 == 1) {
if($i != 0) {
echo(‘</tr>');
}
td means table data which is basically a cell or column
tr stands for table row
The number of td inside your tr will determine how many columns you are going to get.
Also, have a look at the td attribute colspan and rowspan here
In your specific case my guess is that you want to add another td inside your table
<table width="85%" align="center" cellspacing="15">
<tr>
<td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>
<td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>
</tr>
</table>
UPDATE:
to loop through your data you need something like this
echo '<table width="85%" align="center" cellspacing="15">';
echo '<tr>';
$i = 0;
while(...) {
// skip the first iteration
// then after every second <td> close the <tr> and open a newone
if($i > 0 and $i % 2 == 0) {
echo '</tr><tr>';
}
echo '<td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px"></td>';
$i++;
}
echo '</tr>';
echo '</table>';
Try to avoid echo for html code, and use tr for rows and td for
I shall post the code how it works for me:
?>
<table width="85%" align="center" cellspacing="15">
<?php
//query,loop, references
?>
<tr>
<td bgcolor="#dddddd" style="border:1px solid black; padding:12px;">
<form action="index.php" method="get">
<input type="hidden" name="page" value="viewproject">
<input type="hidden" name="projectid" value="<?php $echo projectid;?>">
<input type="submit" value="View Event">
</form>
</td>
<td>
<form action="jump_delete.php" method="post" align="right">
<input type="hidden" name="projectid" value="<?php $echo projectid;?>">
<input type="submit" value="Delete">
</form>
</td>
</tr>
<tr>
<td style="font-weight:bold; font-size:18px;">
<?php echo $projectclient;?>
</td>
<td style="font-size:15px">
Event:<?php echo $projectname;?>
</td>
</tr>
<tr>
<td style="font-size:15px">
Date: <?php echo $duedateformatted;?>
</td>
<td style="font-size:15px">
Staff Count: <?php echo $projectstaffcount;?>
</td>
</tr>
<?php
//close loop
?>
</table>
<?php
tr add rows to you table
td add cells inside a row tr
Assuming you need the additional cell after the second form, you will need an additional <td></td>
echo('<table width="85%" align="center" cellspacing="15">');
//query,loop, references
echo('<tr>
<td bgcolor="#dddddd" style="border:1px solid #000000; padding:12px">
<div style="float:right">
<form action="index.php" method="get">
<input type="hidden" name="page" value="viewproject">
<input type="hidden" name="projectid" value="'.$projectid.'">
<input type="submit" value="View Event"></form>
<br>
<form action="jump_delete.php" method="post" align="right">
<input type="hidden" name="projectid" value="'.$projectid.'">
<input type="submit" value="Delete"></form>
</div>
// Additional td here
</td>
<td>
<div style="font-weight:bold; font-size:18px">'.$projectclient.'</div>
<div style="font-size:15px"><b>Event:</b> '.$projectname.'</div>
<div style="font-size:15px">Date: '.$duedateformatted.'</div>
<div style="font-size:15px">Staff Count: '.$projectstaffcount.'</div>
</td>
</tr>');
Related
I am loading an Ajax form with Smarty and jQuery.
It should load this:
{foreach $topFEED as $article}
<tr>
<td><form action='postbox.php' method='POST'></td>
<td><img class="favicon_prev" src="http://www.google.com/s2/favicons?domain={$article.img_link}"> <input type="text" name="link" style="width: 300px;" value="{$article.link}" READONLY/></td>
{if $loggedin}<td><input type='submit' id="abo" name="submit" value='Abonnieren' /></td>
<input type='hidden' name="action" value='add_feed' READONLY />{/if}
<td></form></td>
</tr>
{/foreach}
Ajax Code:
$.ajax({
type: 'GET',
url: "article.php?method=top_feeds",
dataType: 'html',
})
.done(function(html) {
$("#ajax_top_feeds").replaceWith(html);
});
Result:
<tr>
<td><form action="postbox.php" method="POST"></form></td>
<td><img class="favicon_prev" src="http://www.google.com/s2/favicons?domain=http://www.n-tv.de"> <input type="text" name="link" style="width: 300px;" value="http://www.n-tv.de/rss" readonly=""></td>
<td><input type="submit" id="abo" name="submit" value="Abonnieren"></td>
<input type="hidden" name="action" value="add_feed" readonly=""> <td></td>
</tr>
Your HTML is invalid, the browser is simply correcting it for you. form elements can't cross multiple table cells like that.
You can wrap a form around your entire table:
<form>
<table>
<!--- etc. --->
</table>
</form>
Or you can place a form inside of a table cell:
<table>
<tr>
<td>
<form>
<!--- etc. --->
</form>
</td>
</tr>
</table>
But you can't begin a form in one cell and end it in another. The hierarchy of HTML markup isn't structured that way. Tags must be closed before parent tags are closed.
As you can see i want to have two or more inputs with samo Id and Name, but HTML doesn't allow that, so how can i solve this on some other way and how to make active button change it's color
<table border="0" cellspacing="0" cellpadding = "0" style="font-size:x-small">
<tr valign="bottom" style="height:10px">
<td width="30px" style="vertical-align: top">
</td>
<td width="30px" style="vertical-align: middle" align="center" nowrap="nowrap">
<label style="font-size:small">
Time period</label>
<input type="hidden" id="ReportParameter" value = "1" name="ReportParameter" />
<input class="button" id="showDailyReport" name="searchQueue" type="submit" value="Day" onClick="onClickHandler(this)" />
<input type="hidden" id="ReportParameter" value = "2" name="ReportParameter"/>
<input class="button" id="showWeeklyReport" name="searchQueue" type="submit" value="Week" onClick="onClickHandler(this)" />
</td>
</tr>
</table>
You can define specific class for every button and do the visual changes on that class
ex
<input class="button button-red" id="showDailyReport" name="searchQueue" type="submit" value="Day" onClick="onClickHandler(this)" />
How do I make a radio button automatically check when i press a radio button?
I have 2 tables, when i click a radio button in table1, the radio button in table2 should also be checked.
here is the radio button code for table1
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" alt="COE" class="picture" height="90" width="125"/></td>
<td><p>This service is only available for Meto Manila and Metro Cebu.<p>
<div id='price'> Additional ₱180 </div></td>
</tr>
and here the radio button in table2 that needs to be automatically checked when i check the radio button in table1
<tr>
<td><input type="radio" name="carrier" <?php if (isset($payment) && $payment=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" height="90" width="125"/></td>
<td><p>Pay with your Cash on Delivery (COD)<br>Choose this option if you have selected COD under shipping. Otherwise, choose other options for payment.<p></td>
</tr>
Here are the full codes.
if(isset($_GET['command']) && $_GET['command']=='update'){
$first_name=$_SESSION['first_name'];
$email=$_SESSION['email'];
$home_address=$_SESSION['home_address'];
$mobile_phone=$_SESSION['mobile_phone'];
$carrier=$_REQUEST['carrier'];
$payment=$_REQUEST['payment'];
$result=mysql_query("insert into customers values('','$first_name','$email','$home_address','$mobile_phone','$carrier','$payment')");
$customerid=mysql_insert_id();
date_default_timezone_set("Asia/Hong_Kong");
$date=date('Y-m-d h:i:s');
$result=mysql_query("insert into orders values('','$date','$customerid')");
$orderid=mysql_insert_id();
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_prod_price($pid);
mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
}
header('refresh: 0; url=homeframe.html'); // to be redirected
exit(); // para mawala ang puta, tumigil ang script.
}
// else if(isset($_REQUEST['success']) && $_REQUEST['success']=='1'){
// header('refresh: 0; url=samplebrand.php');
// $message = "Thank you for buying, You will now be redirected";
// echo("<script type='text/javascript'>alert('$message');</script>");
// }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billing Info</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript">
function validate(){
var f=document.form1;
f.command.value='update';
f.submit();
alert("Order submitted");
}
$('#super').change(function(){
var radio1 = $('input:radio[name=carrier]:checked').val();
if(radio1 == 'on'){
$( "input:radio[name=carrier2]" ).prop( "checked", true ).checkboxradio( "refresh" );
}
});
</script>
<style>
#price{
color:red;
font-size:20px;
padding-right: 10px;
font-family: "Times New Roman", Times, serif;
float:right;
}
td{
display:block;
}
</style>
</head>
<body>
<form name="form1" onsubmit="return validate()">
<input type="hidden" name="command" />
<div align="center">
<h1 align="center">Shipping and Payment</h1>
<table border="0" cellpadding="2px">
<tr><td>Order Total:</td><td>₱ <?php echo get_order_total()?></td><td> </td>
</tr>
</table>
<center><h1>Shipping Method</h1></center>
<form method="post">
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td>
<td><img src="img/LBC.jpg" alt="LBC" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p>
<div id='price'> Additional ₱250 </div></td>
</tr>
<tr>
<td><input type="radio" id="super" name="carrier" <?php if (isset($carrier) && $carrier=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" alt="COE" class="picture" height="90" width="125"/></td>
<td><p>This service is only available for Meto Manila and Metro Cebu.<p>
<div id='price'> Additional ₱180 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="Personal") echo "checked";?> value="Personal"></td>
<td><img src="img/buybranded2.jpg" alt="buybranded" class="picture"/></td>
<td><p>The Shipping takes 2-3 days after processing for NCR and 3-5 days for any provincial.<p>
<div id='price'> Additional ₱100 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="NextDayDelivery") echo "checked";?> value="NextDayDelivery"></td>
<td><img src="img/NextdayDelivery.jpg" alt="NextDayDelivery" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p>
<div id='price'> Additional ₱150 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="SameDayDelivery") echo "checked";?> value="SameDayDelivery"></td>
<td><img src="img/Same day Delivery.jpg" alt="SameDayDelivery" class="picture"/></td>
<td><p>Available only for NCR. Get your sporting good/s the same day you purchase the item. Cutoff is 12noon.<p>
<div id='price'> Additional ₱250 </div></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="img/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
<td><p>Office hours: 10:00 am to 6:00 pm<p>
<div id='price'> Free!! </div></td>
</tr>
</table>
<br>
<br>
<center><h1>Payment Method</h1></center>
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'>
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?> value="BPI"></td>
<td><img src="img/BPI.jpg"></td>
<td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td>
</tr>
<!--
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PayPal") echo "checked";?> value="PayPal"></td>
<td><img src="img/paypal.gif"></td>
<td><p>Pay with your PayPal account, credit card (CB, Visa, Mastercard...), or private credit card.<p></td>
</tr>
-->
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="img/cashondelivery.gif"></td>
<td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier2" <?php if (isset($payment) && $payment=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" height="90" width="125"/></td>
<td><p>Pay with your Cash on Delivery (COD)<br>Choose this option if you have selected COD under shipping. Otherwise, choose other options for payment.<p></td>
</tr>
</table>
<table>
<tr><td><!--<input type="submit" value="Place Order"/> --> <input type="button" value="Confirm Order" onclick="window.location='quotation.php?'"></td></tr>
</table>
</form>
</div>
</form>
</body>
</html>
You could achieve this using JQuery. Assuming your forms have ids of form1 and form2:
<script>
$(document).ready(function () {
$("#form1 input[name='carrier']").click(function () {
if (this.checked) {
$("#form2 input[name='carrier']").prop("checked", true);
} // end if checked
});
}); // end doc ready
</script>
You will also need to include a reference to the JQuery library, before adding the aforementioned code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Please note that this will only update the form2 carrier radio button when the form1 button is clicked, and not the other way around.
See this JSFiddle as an example.
i slightly change your second radio name, and you can automatically set it with jquery like below :
$('input:radio[name=carrier]').change(function(){
var radio1 = $('input:radio[name=carrier]:checked').val();
if(radio1 == 'on'){
$( "input:radio[name=carrier2]" ).prop( "checked", true ).checkboxradio( "refresh" );
}
});
DEMO
In a HTML form I am using JavaScript Form validation to avoid empty fields. This is the code for the form:
<form method="post" name="form1" onsubmit="return validateForm()" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Nickname:</td>
<td>
<input type="text" name="nickname" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="email" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Password:</td>
<td><input type="text" name="password" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="estado" value="0">
<input type="hidden" name="MM_insert" value="form1">
</form>
And this is the JavaScript function:
<script>
function validateForm()
{
var x=document.forms["form1"]["nickname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}
</script>
As expected, if the user clicks on the submit button and the field 'nickname' is empty, the Alert Dialog is shown, but after closing it, the form is submitted. I am using Dreamweaver as editor and JQuery Mobile in my web, may be this is the problem.
Any help is welcome.
Working example: http://jsfiddle.net/Gajotres/vds2U/50/
HTML:
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<!--<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>-->
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<div data-role="page" id="index" data-theme="a" >
<div data-role="header">
<h3>
First Page
</h3>
Next
</div>
<div data-role="content">
<form method="post" id="form1" name="form1" action="" data-ajax="false">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Nickname:</td>
<td>
<input type="text" name="nickname" value="" size="32"/>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="email" value="" size="32"/></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Password:</td>
<td><input type="text" name="password" value="" size="32"/></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"/></td>
</tr>
</table>
<input type="hidden" name="estado" value="0"/>
<input type="hidden" name="MM_insert" value="form1"/>
</form>
</div>
<div data-role="footer" data-position="fixed">
</div>
</div>
<div data-role="page" id="second" data-theme="a" >
<div data-role="header">
<h3>
Second Page
</h3>
Back
</div>
<div data-role="content">
</div>
<div data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
JavaScript:
$(document).on('submit', '#form1', function(){
var x=document.forms["form1"]["nickname"].value;
if (x==null || x=="") {
alert("First name must be filled out");
return false;
} else {
return true;
}
});
Changes:
jQuery Mobile has its own way of form handling, you need to disable it if you want to have classic form handling. It is done via attribute data-ajax="false".
Never use inline javascript with jQuery Mobile, I mean NEVER.
For me this is working fine :
<script>
function validateForm()
{
var x=document.forms["form1"]["nickname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}else{
return true;
}
}
</script>
Just added a else statement. It's working fine for me.
I think your code should work. But If not you can make some changes as
Change 1 Remove Submit event from tag
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
Change 2.
Change submit button to default button and validate event here
<input type="button" onclick="javascript:validateForm();" value="Insert record">
Change 3.
Now change in javascript Add code form sub
<script>
function validateForm()
{
var x=document.forms["form1"]["nickname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
}else{
document.forms["form1"].submit();
}
}
</script>
Is it OK to write a form within the tr tag?
<table>
% for my $word ( #$words_2 ) {
<tr>
<form action="/blacklist" method="post">
<td><%=$word%></td>
<td><input type="text" name="data" readonly hidden value="<%=$word%>" /></td>
<td><input class="remove" type="submit" value="Remove" /></td>
</form>
</tr>
% }
</table>
The tr doesn't allow form-tags as direct children. Most modern browsers will let you do a lot of crap and so you could use this - but I wouldn't call it OK. A better approach would be to but the complete form into one of the tds (tds allow text, forms, inline- and block-elements as children):
<table>
<% for my $word ( #$words_2 ) { %>
<tr>
<td><%=$word%></td>
<td>
<form action="/blacklist" method="post">
<input type="text" name="data" readonly hidden value="<%=$word%>" />
<input class="remove" type="submit" value="Remove" />
</form>
</td>
</tr>
<% } %>
</table>
or, a lot easier, simply use a link (but note that data gets sent using GET instead of POST - maybe you'll have to change something in your code that handles the blacklisting):
<table>
<% for my $word ( #$words_2 ) { %>
<tr>
<td><%=$word%></td>
<td>Remove</td>
</tr>
<% } %>
</table>
Is it OK to write a form within the tr tag?
No. Forms can contain tables. Table cells can contain forms.
I'd approach this problem like so:
<form action="/blacklist" method="post">
<fieldset>
<legend>Remove</legend>
% for my $word ( #$words_2 ) {
<label>
<input type="checkbox" name="data" value="<%=$word%>" />
<%=$word%>
</label>
% }
</fieldset>
<input class="remove" type="submit" value="Remove" />
</form>
No, that is not correct. The form tag has to be outside the table or inside a table cell.
Putting the form tag inside the table is an old trick to keep the form from taking up extra space. You should just use CSS for that:
form { margin: 0; padding: 0; }