I have an issue. I want my webpage to allow multiple entries in a table. However some of the column fields POST to search a database and return value which affects the following fields. Currently one entry can be done. However I want to make it into a table where I have an ADD ROW button which I have added javascript to do.
<button id="add_row" >Add Row</button>
<button id="delete_row">Delete Row</button>
<script type="text/javascript">
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html($('#addr0').html());
$('#timeTable').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
Well this works until two things occur. One if I fill in the first field it POSTs and then refreshes the page which won't save the table. I have a working multiple POSTs site which is this example.
$task1 = $_POST["tasks1"];
$task2 = $_POST["tasks2"];
$task3 = $_POST["tasks3"];
$task4 = $_POST["tasks4"];
$task5 = $_POST["tasks5"];
$task6 = $_POST["tasks6"];
$task7 = $_POST["tasks7"];
Now I put this in place for all other aspects of the table, it works. It keeps the data even if I update another box after a refresh. Now I'm wondering if this can be made into an array so it becomes.
$task[x] = $_POST["task[x]"];
The reason I want the _POST to change is because it's a which if they all equal the same then my data is going to go into those, so I do want it to be an array because each of them needs to allow different values.
Basically I want to increment a variable through the javascript and associate it to each added row. I've looked and found "similar" issues but not exactly what I want. This is pretty specific. Finally, I have an even/odd table meaning a format change for every other row in the table. However when I use the Add Row button, it only does the first two rows then after that it no longer keeps the format. Suggestions?
<script type="text/javascript">
$(document).ready(function(){
$("tr:even").css("background-color", "#A71B95");
$("tr:odd").css("background-color", "#F8D3F3");
});
</script>
So after the 2nd row it no longer changes the background color.
Edit 08/08/2018
I've tried to use javascript. Here is what I have currently in the php portion. $text = $_POST["text1"]; $project1 = $_POST["projects1"];
(Mysql) which populates $textA / $textB for selection and $projectsA
and B
<td align='center'>
<?php if(isset($_POST["text1"])){?>
<select id = "text" name="text1" onchange="this.form.submit()">
<option value=''></option>
<? echo $textA; echo $textB;}
else{?>
<select id = "text" name="text1" onchange="this.form.submit()">
<option value=' '> </option>
<? echo $textB;}?>
</select>
</td>
<td align='center'>
<?php if(isset($_POST["submitForm"])){?>
<select name="projects1" onchange="this.form.submit()">
<option value=' '> </option>
<? echo $projectsA;?>
<? echo $projectsB;}
elseif (isset($_POST["text1"])){?>
<select name="projects1" onchange="this.form.submit()">
<option value=' '> </option>
<? echo $projectsA;?>
<? echo $projectsB;}
else{?>
<select name="projects1">
<option value=' '> </option>
<? }?>
</select>
</td>
Here is java
<button id="add_row" >Add Row</button>
<button id="delete_row">Delete Row</button>
<script>
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html($('#addr0').html());
$('#timeTable').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
$("tr:even").css("background-color", "#A71B95");
$("tr:odd").css("background-color", "#F8D3F3");
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
$('#text').change(function(){
var text1 = $('#text').val();
$.post("website.php",
{text1: text},
function(text1)
{
document.getElementsByName('text1').value= text1;
}
);
});
});
</script>
So I'm trying to add a new row, then post the info so that it reads the first column change, then update the selection of the 2nd column based on that change. However I run into problems when I add lines, it refreshes the page and clears everything. Same with after I add rows. I want to add rows that have the same functionality. Hope this helps give a better picture of why I want the post but no refresh. And I want it to come into $_POST['text1'] so it can run the query and update for the next column. and again for every row entered.