2
我試圖從一些選定的div傳遞所有值,其中div的id是我想要獲取並聚合到文本框的值,但我沒有得到任何結果。基本上我想要id
從div
,例如div id="thisOne"
當我點擊。我的腳本是這樣的:來自選定的div的彙總值
<script>
function myFunction(elmnt, clr) {
elmnt.style.backgroundColor = clr;
document.getElementById("allValues").value = document.getElementById(elmnt.value).value;
}
</script>
VIEW:
<form method="POST" action="<?=base_url()?>index.php/dashboard/test_val">
<div id="frame">
<table>
<tbody>
<?php
for($i = 0, $size = count($farm)-1; $i < $size; $i++) {
if($i == 0)
echo '<tr>';
if($flag == 1){
echo '</tr>';
echo '<tr>';
$flag = 0;
}
if($farm[$i]['id_field'] == $farm[$i+1]['id_field']) {
echo '<td>';?>
<div id="<?php echo $farm[$i]['section_name'] ?>" onclick="myFunction(this, 'red')" style="width:60px; height:60px; border:1px solid #aaaaaa;background:#CCFF99">
<center><?php echo $farm[$i]['section_name'] ?></center></div>
<?php echo '</td>';
}else
$flag = 1;
if($i == $size - 1)
echo '</tr>';
}?>
</tbody>
</table>
</div>
<hr>
<div>
<label>Select fertilizer to aplly:</label>
<select name="ChoosenFert">
<?php foreach ($fertilization as $row) : ?>
<option value="<?php echo $row['id'] ?>"> <?php echo $row['type'] ?> </option>
<?php endforeach;?>
</select>
<br />
<button>Apply Fertilizer</button>
<input type="text" id="allValues" name="allValues" hidden>
</div>
</form>
控制器:
public function test_val(){
$inputData = $this->input->post("allValues");
echo $inputData;
}
爲什麼他們不斷添加'PHP'代碼而不是'HTML' – Tushar
HTML和JavaScript或需要代碼需要? –
html和jquery需要 –