I have a HTML Table with multible Table Rows and Columns.
There is a data request to an SQL Database.
The data is then displayed in the table body.
The table headers stay the same.
But now the problem. i don't know why all the data is written in the first column of my html table.
The table headers do not match the data be
let table = < HTMLTableElement > document.getElementById("result1");
let row = table.insertRow(-1);
let cell1 = row.insertCell(0);
let cell2 = row.insertCell(1);
let cell3 = row.insertCell(2);
let cell4 = row.insertCell(3);
let cell5 = row.insertCell(4);
let cell6 = row.insertCell(5);
let cell7 = row.insertCell(6);
cell1.innerHTML = data[i].projekt_nr;
cell2.innerHTML = data[i].projekt_name;
cell3.innerHTML = data[i].inhalt;
cell4.innerHTML = data[i].bauort;
cell5.innerHTML = data[i].standort;
cell6.innerHTML = datum[i];
cell7.innerHTML = nutzer[i];
<table id="bestand">
<thead>
<tr>
<th>Projekt Nummer</th>
<th>Projekt Name</th>
<th>Inhalt</th>
<th>Bauort</th>
<th>Standort</th>
<th>Ausleihdatum</th>
<th>Nutzer</th>
</tr>
<tr>
<td><input type="text" [(ngModel)]="query_1" (ngModelChange)="search_1()"></td>
<td><input type="text" [(ngModel)]="query_2" (ngModelChange)="onSearch_2()"></td>
<td><input type="text" [(ngModel)]="query_3" (ngModelChange)="onSearch_3()"></td>
<td><input type="text" [(ngModel)]="query_4" (ngModelChange)="onSearch_4()"></td>
<td><input type="text" [(ngModel)]="query_5" (ngModelChange)="onSearch_5()"></td>
<td><input type="text" [(ngModel)]="query_6" (ngModelChange)="onSearch_6()"></td>
<td><input type="text" [(ngModel)]="query_7" (ngModelChange)="onSearch_7()"></td>
</tr>
</thead>
<tbody id="result1">
</tbody>
</table>
See the following picture.
all the data is displayed in the first column. usually the data should match the table headers and the input fields
<table id="bestand">
<tr class="header">
<th>Projekt Nummer</th>
<th>Projekt Name</th>
<th>Inhalt</th>
<th>Bauort</th>
<th>Standort</th>
<th>Ausleihdatum</th>
<th>Nutzer</th>
</tr>
<tr class="header">
<td><input type="text" [(ngModel)]="query_1" (ngModelChange)="search_1()"></td>
<td><input type="text" [(ngModel)]="query_2" (ngModelChange)="search_2()"></td>
<td><input type="text" [(ngModel)]="query_3" (ngModelChange)="onSearch_3()"></td>
<td><input type="text" [(ngModel)]="query_4" (ngModelChange)="onSearch_4()"></td>
<td><input type="text" [(ngModel)]="query_5" (ngModelChange)="onSearch_5()"></td>
<td><input type="text" [(ngModel)]="query_6" (ngModelChange)="onSearch_6()"></td>
<td><input type="text" [(ngModel)]="query_7" (ngModelChange)="onSearch_7()"></td>
</tr>
</table>
Related
I haven't played with HTML in over 15 years, and I've never done any other coding (I know... I'm a delight already, yeah?). This is only to be opened in browser on an offline PC for little kids. It's part of a homebrew html-based adventure game. I harvested code from several other sites to get this small bit - but idk how to make it work. I'd like kids to be able to answer the questions appropriately, and then save them as a text document (or really saved any way possible that I can view later) in the Downloads folder or any folder. There is no 'server' or any network - this is an old Windows 98 that kids play on.
edit:Something similar to this download function:https://stackoverflow.com/a/29376481/14739116
Here is what I have - please feel free to murder it:
<html><head>
<title>What did I do today?</title>
</head><body>
<form onsubmit="download(this['name'].value, this['form'].value)">
<h3>My name is...
<br>
<textarea rows=2 cols=25 name="text"></textarea>
<br><br>
Please select the appropriate response.
<table width="660" border>
<tr align="center">
<td width="500"></td>
<td width="50">1</td>
<td width="50">2</td>
<td width="50">3</td>
<td width="50">4</td>
</tr>
<tr align="center">
<td width="500">I brushed my teeth today.</td>
<td><input type="checkbox" id="1"></td>
<td><input type="checkbox" id="2"></td>
<td><input type="checkbox" id="3"></td>
<td><input type="checkbox" id="4"></td>
</tr>
<tr align="center">
<td width="500">I washed my hands today.</td>
<td><input type="checkbox" id="1"></td>
<td><input type="checkbox" id="2"></td>
<td><input type="checkbox" id="3"></td>
<td><input type="checkbox" id="4"></td>
</tr>
<tr align="center">
<td width="500">I ate all of my vegetables today.</td>
<td><input type="checkbox" id="1"></td>
<td><input type="checkbox" id="2"></td>
<td><input type="checkbox" id="3"></td>
<td><input type="checkbox" id="4"></td>
</tr>
<tr align="center">
<td width="500">I fed the fish this week.</td>
<td><input type="checkbox" id="1"></td>
<td><input type="checkbox" id="2"></td>
<td><input type="checkbox" id="3"></td>
<td><input type="checkbox" id="4"></td>
</tr>
</table>
<br>
<input type="submit" value="SAVE">
</body></html>
Your HTML is workable, though the main issue I see with it is the duplicate ids (which is invalid) -- what you would want instead is to set the value attribute.
The good thing is, you won't need a server or anything for downloading the responses as a file, as that can be done in JavaScript. You can try some of the solutions discussed here: JavaScript: Create and save file. (You just need to make sure the browser settings will download the file to your desired location by default).
You would also need to write some JS to extract the selected checkboxes & the entered name (which would be a suitable filename -- with some appropriate sanitization).
I assume on an old system like that, there's probably an old version of IE. If so, you'll be more limited with JS functionality. (If possible, try installing a later version or another browser to get things working).
Below is a snippet that works on Firefox/Chrome and IE10+ (also available in this fiddle).
The latter half of it is based on the answer that I previously linked here.
The JS will generate a CSV format of the answers and use the entered name as the filename.
You just need to set the browser settings to automatically download to your desired folder.
<html>
<head>
<title>What did I do today?</title>
</head>
<body>
<form onsubmit="saveResponses()">
<h3>My name is...</h3>
<textarea rows=2 cols=25 name="text"></textarea>
<br><br>
Please select the appropriate response.
<table width="660" border>
<tr align="center">
<td width="500"></td>
<td width="50">1</td>
<td width="50">2</td>
<td width="50">3</td>
<td width="50">4</td>
</tr>
<tr align="center">
<td width="500">I brushed my teeth today.</td>
<td><input type="checkbox" value="1"></td>
<td><input type="checkbox" value="2"></td>
<td><input type="checkbox" value="3"></td>
<td><input type="checkbox" value="4"></td>
</tr>
<tr align="center">
<td width="500">I washed my hands today.</td>
<td><input type="checkbox" value="1"></td>
<td><input type="checkbox" value="2"></td>
<td><input type="checkbox" value="3"></td>
<td><input type="checkbox" value="4"></td>
</tr>
<tr align="center">
<td width="500">I ate all of my vegetables today.</td>
<td><input type="checkbox" value="1"></td>
<td><input type="checkbox" value="2"></td>
<td><input type="checkbox" value="3"></td>
<td><input type="checkbox" value="4"></td>
</tr>
<tr align="center">
<td width="500">I fed the fish this week.</td>
<td><input type="checkbox" value="1"></td>
<td><input type="checkbox" value="2"></td>
<td><input type="checkbox" value="3"></td>
<td><input type="checkbox" value="4"></td>
</tr>
</table>
<br>
<input type="submit" value="SAVE">
</form>
<script type="text/javascript">
// StackOverflow question https://stackoverflow.com/questions/65084239
function saveResponses() {
// Windows-safe filename
var name = document.getElementsByTagName('textarea')[0].value.replace(/[<>:"/\|?*]/g, ' ') + '.txt';
var responses = [];
var questions = document.getElementsByTagName('tr');
for (var i = 1; i < questions.length; i++) {
var question = questions[i].getElementsByTagName('td')[0].innerHTML;
// Save responses in CSV format
responses.push('"' + question + '"');
var checkboxes = questions[i].querySelectorAll('input[type=checkbox]:checked');
for (var j = 0; j < checkboxes.length; j++) {
responses[responses.length - 1] += ',"' + checkboxes[j].value + '"';
}
}
responses = responses.join('\r\n');
// console.log(responses);
download(responses, name, 'text/plain');
}
// Borrowed from https://stackoverflow.com/a/30832210
function download(data, filename, type) {
var file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) { // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
} else { // Others
var a = document.createElement('a');
var url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
</script>
</body>
</html>
In the first row, I have four columns. Rows 2-4 I have 2, to help with formatting. Is there a more graceful way to do this in order to avoid the validation warning?
This is just for a school project, nothing intense or anything, but I would like to get it right.
<div>
<h2>Personal Information</h2>
<form method="post">
<table class = "center">
<tr>
<td style = "text-align:right;">First Name:</td>
<td>
<input name = "fname" type = "text"
size = "25" maxlength = "20"
required autofocus>
</td>
<td>Last Name:</td>
<td>
<input name = "lname" type = "text"
size = "25" maxlength = "20">
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<input name = "email" type = "email"
placeholder = "e.g., JohnDoe#example.com"
size = "25"
required title = "Must be a valid email address">
</td>
</tr>
<tr>
<td style = "text-align:right;">Gender:</td>
<td style = "text-align:left">
<label>Male</label>
<input name = "gender" type = "radio"
value = "Male">
<label>Female</label>
<input name = "gender" type = "radio"
value = "Female">
</td>
</tr>
<tr>
<td style = "text-align:right;">Age Group:</td>
<td style = "text-align:left">
<label>Under 21</label>
<input name = "under" type = "checkbox"
value = "under">
<label>21 - 40</label>
<input name = "to" type = "checkbox"
value = "to">
<label>Over 40</label>
<input name = "over" type = "checkbox"
value = "over">
</td>
</tr>
</table>
</form>
</div>
for the rows you have only 2 columns you can use colspan to make a cell span multiple columns so everything lines up.
Ex:
<tr>
<td>Email Address:</td>
<td colspan="3">
<input name = "email" type = "email" placeholder = "e.g., JohnDoe#example.com" size = "25" required title = "Must be a valid email address">
</td>
</tr>
i have a table of data with array input values , as like below
<table>
<tr>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
</tr>
<tr>
<td><input type="text" name="user_id[]" value="1"></td>
<td><input type="text" name="name[]"></td>
<td><input type="text" name="email[]"></td>
<td><input type="text" name="phone[]"></td>
</tr>
<tr>
<td><input type="text" name="user_id[]" value="2"></td>
<td><input type="text" name="name[]"></td>
<td><input type="text" name="email[]"></td>
<td><input type="text" name="phone[]"></td>
</tr>
<tr>
<td><input type="text" name="user_id[]" value=""></td>
<td><input type="text" name="name[]"></td>
<td><input type="text" name="email[]"></td>
<td><input type="text" name="phone[]"></td>
</tr>
<tr>
<td><input type="text" name="user_id[]" value=""></td>
<td><input type="text" name="name[]"></td>
<td><input type="text" name="email[]"></td>
<td><input type="text" name="phone[]"></td>
</tr>
</table>
And i m trying to update the first two rows with user_id value and trying to insert last two rows as new rows.
I m using the below insert query in laravel controller :
if(!empty(Input::get('user_id')))
{
for($i = 0; $i < count(Input::get('name')); $i++)
{
$id = Input::get('user_id')[$i];
$data = User::find($id);
$data->name = Input::get('name')[$i];
$data->email = Input::get('email')[$i];
$data->phone = Input::get('phone')[$i];
$data->save();
}
}
if(empty(Input::get('user_id')))
{
for($i = 0; $i < count(Input::get('name')); $i++)
{
$new = new User();
$new->name = Input::get('name')[$i];
$new->email = Input::get('email')[$i];
$new->phone = Input::get('phone')[$i];
$new->save();
}
}
But its not working properly . can somebody suggest me any solution for this ?
You should be using a foreach loop to, well, loop through the fields and do something if it is empty or not.
Maybe, something like this would help you.
$fields = Input::get('user_id');
foreach($fields as $field)
{
if(! empty($field))
{
// field is not empty
// update here
}
else
{
// field is empty
// do something here
}
}
In express, when I do a post from a form:
<tr>
<td><input type="text" name="name"></td>
<td><input type="text" name="remarks"></td>
</tr>
<tr>
<td><input type="text" name="name"></td>
<td><input type="text" name="remarks"></td>
</tr>
var body = req.body;, body give me this:
{ name: [ 'Tel', 'Tel2' ], remarks ['test1','test2'] }
How can I get this in json array:
{debtor: [{name:'Tel', remarks:'test1'}, {name:'Tel2', remarks:'test2'} ]
If the remarks test1 is empty, I wont be able to know test2 is belong to row 1 or row2.
Just transform the req.body object as you wish.
var body = [];
for(var n=0; n<req.body.name.length; n++){
body.push({name : req.body.name[n], remarks : req.body.remarks[n]});
}
G'day,
As a part of my assignment, I have to store the details entered by a user in a registration form into an XML document.
I have managed to do that BUT the problem is when a new user registers, the old details are over-written with the details of the new user. So, there is ONLY 1 user details in the XML document in the end.
I was wondering if there's any way to save the details of new user while "preserving" the old details.
Any help is appreciated :)
HTML Code -
<form id="rego" name="rego" method="get" action="register2.php">
<table width="719" border="0">
<tr>
<td><div align="right">Email Address</div></td>
<td><label for="email"></label>
<input type="text" name="email" id="email" maxlength="50" /></td>
</tr>
<td width="376"><div align="right">First Name</div></td>
<td width="333"><label for="firstName"></label>
<input type="text" name="firstName" id="firstName" maxlength="15" /></td>
<td><div id="underInput"></div></td>
</tr>
<tr>
<td><div align="right">Last Name</div></td>
<td><label for="lastName"></label>
<input type="text" name="lastName" id="lastName" maxlength="20" /></td>
</tr>
<tr>
<td><div align="right">Phone Number</div></td>
<td><label for="phoneNumber"></label>
<input type="text" name="phoneNumber" id="phoneNumber" maxlength="10" /></td>
</tr>
<tr>
<tr>
<td><div align="right">Password</div></td>
<td><label for="password"></label>
<input type="password" name="password" id="password" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">Re-type password</div></td>
<td><label for="confirmPassword"></label>
<input type="password" name="confirmPassword" id="confirmPassword" maxlength="30" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="Submit" name="Submit" id="Submit" value="Submit"/><!--onclick="saveForm();"--></td>
</tr>
PHP Code (I'm using DOM) -
<?php
$CustomerEmail = $_GET["email"];
$CustomerFName = $_GET["firstName"];
$CustomerLName = $_GET["lastName"];
$CustomerPhoneNumber = $_GET["phoneNumber"];
$CustomerPassword = $_GET["password"];
$CustomerConfirmPassword = $_GET["confirmPassword"];
$doc = new DomDocument('1.0');
$root = $doc->createElement('customers');
$root = $doc->appendChild($root);
$customer = $doc->createElement('customer');
$customer = $root->appendChild($customer);
$email = $doc->createElement('email');
$email = $customer->appendChild($email);
$valueEmail = $doc->createTextNode($CustomerEmail);
$valueEmail = $email->appendChild($valueEmail);
$fName = $doc->createElement('firstname');
$fName = $customer->appendChild($fName);
$valueFName = $doc->createTextNode($CustomerFName);
$valueFName = $fName->appendChild($valueFName);
$lName = $doc->createElement('lastname');
$lName = $customer->appendChild($lName);
$valueLName = $doc->createTextNode($CustomerLName);
$valueLName = $lName->appendChild($valueLName);
$phone = $doc->createElement('phone');
$phone = $customer->appendChild($phone);
$valuePhone = $doc->createTextNode($CustomerPhoneNumber);
$valuePhone = $phone->appendChild($valuePhone);
$password = $doc->createElement('password');
$password = $customer->appendChild($password);
$valuePassword = $doc->createTextNode($CustomerPassword);
$valuePassword = $password->appendChild($valuePassword);
$confirmPassword = $doc->createElement('confirmpassword');
$confirmPassword = $customer->appendChild($confirmPassword);
$valueConfirmPassword = $doc->createTextNode($CustomerConfirmPassword);
$valueConfirmPassword = $confirmPassword->appendChild($valueConfirmPassword);
$doc->save('customer2.xml');
?>
I apologise for any inconvience.
You need to load your existing file, before creating a new one each time and override the previous.
.....
$doc = new DomDocument('1.0');
if($xml = file_get_contents( 'customer2.xml')){
$doc->loadXML( $xml, LIBXML_NOBLANKS );
$root=$doc->getElementsByTagName('customers')->item(0);
}else{
$root = $doc->createElement('customers');
$root = $doc->appendChild($root);
}
$customer = $doc->createElement('customer');
$customer = $root->appendChild($customer);
.....
$doc->save('customer2.xml');