|
|
|
ทำ dynamic input get ค่ามาแล้วแต่ยังไม่ได้ตามต้องการ |
|
|
|
|
|
|
|
คือทำ dynamic input ครับแล้วที่ทำมาออกแบบนี้
index0 value= 1
Notebook Computer PC
index1 value= 2
Notebook Computer PC
อยากจะ get ค่าให้เป็นตามนี้ ไม่รู้จะแยกยังไง
index0 value= 1
Notebook
index1 value= 2
Computer PC
Jquery
Code (PHP)
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 4; //maximum input boxes allowed
var x = 1; //initlal text box count
$('#button-add').click(function(e){
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$('.wrap:first').clone().insertAfter(".wrap:last"); //we select the box clone it and insert it after the box
}
});
$(document).on("click", "#button-remove", function() {
if ($('.wrap').length > 1){
$(this).closest(".wrap").remove();
}
});
});
</script>
Code (PHP)
<script type="text/javascript">
$(document).ready(function(){
$('#test').on('click', function(){
var values = "";
$("input[name=amount]").each(function (index, value) {
var values =+ $(this).val() + "\n";
var type = $('select[name="type"] option:selected').text();
console.log('index'+index + ' value= '+values);
});
//console.log('value= '+values);
// $('select#type').find('option').each(function() {
//var type = $('select[name="type"] option:selected').text();
//console.log('selected='+type);
// });
});
});
</script>
HTML
Code (PHP)
<div class="row wrap">
<div class="form-group col-md-3">
<label for="type">หมวดหมู่ :</label>
<select name="type" id="type" class="form-control required">
<option value="">กรุณาเลือกหมวดหมู่</option>
<?php
$select = $db->prepare('SELECT id,type FROM tbl_type');
$select->execute();
$count = $select->rowCount();
while ($dataselect = $select->fetch(PDO::FETCH_ASSOC)){
?>
<option value="<?php echo $dataselect["id"];?>"> <?php echo $dataselect["type"];?></option>
<?php
}
?>
</select>
</div>
<div class="form-group col-md-2">
<label for="amount">จำนวน :</label>
<input type="text" name="amount" id="amount" class="form-control required" >
</div>
<div class="col-md-1" style="padding-top: 30px;">
<input class="btn btn-xs btn-danger" type="button" id="button-remove" value="-">
</div>
</div>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2016-11-18 23:20:15 |
By :
littlebeer |
View :
791 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ประวัติการแก้ไข 2016-11-19 15:13:46
|
|
|
|
Date :
2016-11-19 15:09:48 |
By :
Luz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
$('select[name="type"] option:selected').each(function (index, value) {
var values =+ $(this).val() + "\n";
var type = $(this).text();
console.log('index type'+index + 'type = '+type + ' value select= '+values);
});
|
|
|
|
|
Date :
2016-11-19 16:00:24 |
By :
Luz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|