Right now I have a table that looks like this:
The HTML for this table looks like this (I only included a brief snippet because the rest of the HTML looks the same):
<table class="table table-bordered table-condensed">
<tr>
<th>Days</th>
<th>Date</th>
<th>Calories</th>
<th>Happiness</th>
<th>Hunger</th>
<th>Motivation</th>
</tr>
<tr>
<td>1</td>
<td id="day">{{dayArray[0]}}</td>
<td id="calorie">{{calorieArray[0]}}</td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
</tr>
<tr>
<td>2</td>
<td id="day">{{dayArray[1]}}</td>
<td id="calorie">{{calorieArray[1]}}</td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
</tr>
<tr>
<td>3</td>
<td id="day">{{dayArray[2]}}</td>
<td id="calorie">{{calorieArray[2]}}</td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
</tr>
<tr>
I am using an array to populate the date because dependent on what the user chooses earlier on in the page, the date changes. The same goes for calories. I am using AngularJS's data binding to do this.
Does anyone have an idea of how to change the table's HTML to make it less repetitive? I have heard that anytime you begin to start copying and pasting things, it's a sign that you're writing bad code :(
use an ng-repeat
<table class="table table-bordered table-condensed">
<tr>
<th>Days</th>
<th>Date</th>
<th>Calories</th>
<th>Happiness</th>
<th>Hunger</th>
<th>Motivation</th>
</tr>
<tr ng-repeat="day in dayArray">
<td>{{ $index + 1 }}</td>
<td id="day-{{$index}}">{{day}}</td>
<td id="calorie-{{$index}}">{{calorieArray[$index]}}</td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
<td><input placeholder="0" /></td>
</tr>
Related
I have a ColdFusion form that I want to update my database. I am using the record ID, but there's a issue. When I type the url - localhost:8500/elephant_shack/update.cfm?record_id=1 I get to the for, but not with the form. I am a totally newbie and am lost!
Any help would be great :)
<!--- form--->
<cfquery name="GetRecordtoUpdate" datasource="elephant_shack">
SELECT *
FROM Richard
WHERE record_id = #URL.record_id#
</cfquery>
<table>
<cfoutput query= "GetRecordtoUpdate">
<form action="update_action.cfm" method="Post">
<tr>
<td width="93">record id:</td>
<td width="286"><input name="record_id" type="text" value="#record_id#" size="25"></td>
</tr>
<tr>
<td width="93">Item:</td>
<td width="286"><input name="item" type="text" value="#item#" size="25"></td>
</tr>
<tr>
<td>Stock:</td>
<td><input name="stock" type="text" value="#stock#" size="12"></td>
</tr>
<tr>
<td>Par:</td>
<td><input name="par" type="text" value="#par#" size="12"></td>
</tr>
<tr>
<td>Order:</td>
<td><input name="order" type="text" value="#order#" size="50"></td>
</tr>
<tr>
<td> </td>
<td><input type="Submit" value="Update Information"></td>
</tr>
</form>
</cfoutput>
</table>
Also, the database is not being updated.
<!--- update form--->
<cfupdate datasource="elephant_shack" tablename="Richard">
i have the following html to Capture some Data.
<fieldset>
<legend>Rezept hinzufügen</legend>
<form action="php_act/create.php" method="post">
<table cellspacing="0" cellpadding="0">
<tr>
<th>Rezept Name</th>
<td><input type="text" name="name" placeholder="Rezept Name" /></td>
</tr>
<tr>
<th>Kurzbeschreibung</th>
<td><input type="text" name="kurztext" placeholder="Kurzbeschreibung" class="kurztext" /></td>
</tr>
<tr>
<th>Kategorie</th>
<td><input type="text" name="Kategorie" placeholder="Kategorien - mit , trennen" /></td>
</tr>
<tr>
<th>Anforderung</th>
<td><select name="Anforderung">
<option value="einfach">einfach</option>
<option value="mittel">mittel</option>
<option value="schwer">schwer</option>
</select></td>
</tr>
<tr>
<th>Zeit / Nährwerte</th>
<td><input type="text" name="zeit" placeholder="Zeit in minuten" /></td>
<td><input type="text" name="KCAL" placeholder="KCAL" size="6"/></td>
<td><input type="text" name="KH" placeholder="KH" size="6"/></td>
<td><input type="text" name="Eiweiss" placeholder="Eiweiss" size="6"/></td>
<td><input type="text" name="Fett" placeholder="Fett" size="6" /></td>
</tr>
<tr>
<th>Portionen</th>
<td><input type="text" name="Portionen" placeholder="Portionen" /></td>
</tr>
<tr>
<th>Zutaten</th>
<td><input type="text" name="zutaten" placeholder="Zutaten" /></td>
</tr>
<tr>
<th>Zubereitung</th>
<td><input type="text" name="zubereitung" placeholder="Zubereitung" /></td>
</tr>
<tr>
<th>FotoliaID</th>
<td><input type="text" name="FotoliaID" placeholder="FotoliaID" /></td>
</tr>
<tr>
<td><button type="submit">Speichern</button></td>
<td><button type="button">zurück</button></td>
</tr>
</table>
</form>
</fieldset>
There are some Input Type Text. i need to capture line breaks within the textfields. Problem is that "Enter" submits by default the. Is it possible to change that. Enter should add a line break in the textfield and not submit the form.
Can't you use textarea instead of textbox?
In a textarea you can insert enters.
https://www.w3schools.com/tags/tag_textarea.asp
I've created a simple HTML5 form, with the code below.
It successfully works in Chrome in W10, as well as in Chrome on my Android Phone.
The autosum function doesn't work on an iPad in Safari, nor Chrome.
What am I missing?
Cheers,
Stewart
<form onsubmit="return false" oninput="tta.value = parseInt(r1ta.value)+parseInt(r2ta.value)+parseInt(r3ta.value)+parseInt(r4ta.value);ttb.value = parseInt(r1tb.value)+parseInt(r2tb.value)+parseInt(r3tb.value)+parseInt(r4tb.value);te.value = parseInt(r1e.value)+parseInt(r2e.value)+parseInt(r3e.value)+parseInt(r4e.value)">
<table style="height: 97px;" width="216">
<tbody>
<tr>
<td>RINK</td>
<td>TEAM A</td>
<td>TEAM B</td>
<td>ENDS</td>
</tr>
<tr>
<td>1</td>
<td><input id="r1ta" name="r1ta" type="number" /></td>
<td><input id="r1tb" name="r1tb" type="number" /></td>
<td><input id="r1e" name="r1e" type="number" /></td>
</tr>
<tr>
<td>2</td>
<td><input id="r2ta" name="r2ta" type="number" /></td>
<td><input id="r2tb" name="r2tb" type="number" /></td>
<td><input id="r2e" name="r2e" type="number" /></td>
</tr>
<tr>
<td>3</td>
<td><input id="r3ta" name="r3ta" type="number" /></td>
<td><input id="r3tb" name="r3tb" type="number" /></td>
<td><input id="r3e" name="r3e" type="number" /></td>
</tr>
<tr>
<td>4</td>
<td><input id="r4ta" name="r4ta" type="number" /></td>
<td><input id="r4tb" name="r4tb" type="number" /></td>
<td><input id="r4e" name="r4e" type="number" /></td>
</tr>
<tr>
<td>TOTAL</td>
<td><output for="r1ta r2ta r3ta r4ta" name="tta"></output></td>
<td><output for="r1tb r2tb r3tb r4tb" name="ttb"></output></td>
<td><output for="r1e r2e r3e r4e" name="te"></output></td>
</tr>
</tbody>
</table>
</form>
Because your field's default value is not 0 it is null. so it cannot be able to sum 1 + null for ins.
Ok, now, I invented tf for table
<table>
<tr>
<td><b>User Name</b></td>
<td><input type="text" name="userName" /></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<tf colspan="2" align="center"><input type="submit" value="Login" /></tf>
</tr>
</table>
It somehow works but the tf row jump on top.
How to fix?
You can't just invent new tags and expect the browser to know what to do.
Besides from that, I believe you are looking for a proper utilization of the tfoot tag, like it is described here: http://www.w3schools.com/tags/tag_tfoot.asp
So what you want to do is:
<table>
<tbody>
<tr>
<td><b>User Name</b></td>
<td><input type="text" name="userName" /></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" name="password" /></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2" align="center"><input type="submit" value="Login" /></td>
</tr>
</tfoot>
</table>
This simply happens because the <table> tag does not recognize <tf>. <td> and <tr> are tags that link to the table tag which is why they appear correctly. The only way to use unrelated tags are within the <td> tags.
The unrelated tag <tf> gets thrown out of the table because of this and this is why it is shown above the table
Edit: The selected answer contains a link to the working fiddle I was able to compose without the use of a nested table.
I want to semantically code a table in HTML with a layout like the picture below. Unfortunately I haven't been able to find anything quite like it here on the network.
I have been able to force the look by manually setting cell widths, but I want to make sure the code I'm producing makes sense, and I don't think that's the case, because without manually setting the widths, standard rendering looks more like the following picture.
So far, the problematic code I have come up with looks like this:
<table>
<thead>
<tr>
<th scope="col">Type of Loss Dollar</th>
<th scope="col">Reserve Amount</th>
<th scope="col">Paid Amount</th>
<th scope="col">Total This Loss</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">
<table>
<tbody>
<tr>
<th scope="row">Medical</th>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr><tr>
<th scope="row">Indemnity</th>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr><tr>
<th scope="row">Expense</th>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr>
</tbody>
</table>
</td><td>
TOTAL
</td>
</tr>
</tbody>
</table>
Without the images it's a bit hard to say, but I think a better solution than nested tables would be to simply use the colspan and rowspan attributes.
Edit: Seeing the images I'd say you can most definitely achieve that using rowspan (and colspan the way you're using it already).
Also, you don't need to set the scope attribute if it's "col". It defaults to "col".
Edit: As Marat Tanalin points out the scope attribute's default value is actually auto which "makes the header cell apply to a set of cells selected based on context". And which in my experience acts exactly the same as setting it to "col" (for screenreaders).
Edit: Here are two great articles on marking up advanced tables: http://www.456bereastreet.com/archive/200910/use_the_th_element_to_specify_row_and_column_headers_in_data_tables/ & http://www.456bereastreet.com/archive/200410/bring_on_the_tables/
Edit: Here is the fiddle exhibiting desired behavior (visually at least) and the source code of that fiddle follows:
<table border="1">
<thead>
<tr>
<th>Status</th>
<th>Type of Loss Dollar</th>
<th>Reserve Amount</th>
<th>Paid Amount</th>
<th>Total This Loss</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">Open</td>
<td>Medical</td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td rowspan="3">TOTAL</td>
</tr><tr>
<td>Indemnity</td>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr><tr>
<td>Expense</td>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr>
</tbody>
</table>
yep, as all the peeps above suggested, it's all about the rowspan.
here's a re-write of your code:
<table>
<thead>
<tr>
<th>Type of Loss Dollar</th>
<th>Reserve Amount</th>
<th>Paid Amount</th>
<th>Total This Loss</th>
<th>Last Heading</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3"></td>
<td>Medical</td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td rowspan="3">TOTAL</td>
</tr><tr>
<td>Indemnity</td>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr><tr>
<td>Expense</td>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr>
</tbody>
</table>