I have these Dynamic user inputs with following types:
- Costs:
<selection>The user will choose 1 option - Money Input: user input some text.I got after help.
I want Theses 2 values given above.
I want to get the Values of these Dynamic user inputs using JavaScript.
Here the Code given below : Update:solved
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-collapse: collapse;
}
</style>
<script>
function addMore() {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(-1);
var cell2 = row.insertCell(-1);
var x = document.getElementById("myTable").rows[1].cells;
cell1.innerHTML = x[0].innerHTML;
cell2.innerHTML = x[1].innerHTML;
}
function removeLast() {
document.getElementById("myTable").deleteRow(-1);
}
</script>
</head>
<body>
<form action="payroll.php" method="post">
<table id="myTable">
<tr>
<th>Costs</th>
<th>Money Input</th>
</tr>
<tr>
<td>
<select class="mySelect" name="DESCR" >
<option disabled="" selected="">Select</option>
<option value="BASIC PAY">BASIC PAY</option>
<option value="GAS BILL">GAS BILL</option>
<option value="CLUB">CLUB</option>
<option value="MEDICINE">MEDICINE</option>
<option value="BANK LOAN">BANK LOAN</option>
</select>
</td>
<td> <input type="text" name="ALAMT"></td>
</tr>
</table>
</form>
<br>
<button onclick="addMore()">Add More</button>
<button onclick="removeLast()">Remove</button>
<button onclick="myFunction()">Try it</button>
</body>
<script>
function myFunction() {
var select = document.getElementById("myTable").rows[1].cells[0].firstElementChild;
var selectValue = select.options[select.selectedIndex].value;
var ocell = document.getElementById("myTable").rows[1].cells[1];
alert("Selected Index: "+selectValue+"\nInput value: "+ocell.firstElementChild.value);
}
</script>
</html>
Using this code every i get errors.But i want the <option> value that is only chosen by the user, instead off all.
Please suggest me how can i do this or more better alternatives to do it. please let me know for any further information.Thanks