My script in custom file not working

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
SOHIB
User
Posts: 93

My script in custom file not working

Post by SOHIB »

Hello All friends

i am tring to use custom php file ,with small script ,but it is not working ,please help

this is the file code

<?php
function fill_unit_select_box()
{
$qp=Conn()->execute("select acc_group from account_type ");
$ROWS = $qp->GetRows();
if (count($ROWS) > 0) {
foreach($ROWS AS $ROW){
$acgroup=$ROW['acc_group'];
$output.='<option value="'.$ROW["acc_group"].'">'.$ROW["acc_group"].'</option>';
}}
return $output;
}
?>


<html>
<head>
</head>
<body>
<form method="post" id="insert_form">
<div class="table-responsive">
<table class="table table-bordered"id="item_table">
<tr>
	<th>الحساب</th>
	<th>الحساب الفرعي</th>
	<th><button type="button"name="add"class="add">
	<span class="glyphicon glyphicon-plus"></span></button></th>
</tr>
</table>
<br>
<div align="center">
<input type="submit"name="submit" class="btn btn-info"value="insert">
</div>
</div>
</form>
</body>
</html>

<script>
$(document).ready(function(){
$(document).on('click','.add',function(){
var html='';
html+='<tr>';
html+='<td><input type="text"name="item_name[]"class="form-control item_name />"></td>';
html+='<td><input type="text"name="item_name1[]"class="form-control item_name1 />"></td>';
html+='<select name="accg[]"><optin value"">slect accoungroup</option><?php echo fill_select_unit_box();?></select></td>';
html+='<td><button type="button"name="remove"class="btn btn-danger btn-sm remove"><span class="glyphicon glyphicon-minus"></span></button></td><tr>';
$('#item_table').append(html);
)};
)};
</script>

mobhar
User
Posts: 11660

Post by mobhar »

Press [F12] from your browser, and check whether any Javascript error message from Console section.


arbei
User
Posts: 9286

Post by arbei »

SOHIB wrote:

<input type="submit"name="submit" class="btn btn-info"value="insert">

You should change the type to "button".


SOHIB
User
Posts: 93

Post by SOHIB »

i have try to test the alert function ,but it is not display so I think jQuery is not working with me,

<script>

$(document).ready(function(){
alert('hello');
$(document).on('click','.add',function(){
var html='';
html+='<tr>';
html+='<td><input type="text"name="item_name[]" /></td>';
html+='<td><input type="text"name="item_name1[]" /></td>';
html+='<td><select><option>select accoungroup</option>'
.'<?php  echo fill_unit_select_box();?>'.'</select></td>';
html+='<td><button type="button"name="remove"><span >-</span></button></td></tr>';
$('#item_table').append(html);
});
});
</script>

arbei
User
Posts: 9286

Post by arbei »

Rememeber that scripts are loaded asynchronously, you need to wait until jQuery is loaded, e.g.

<script>
loadjs.ready("jquery", function() {
// your code
});
</script>

SOHIB
User
Posts: 93

Post by SOHIB »

Thank you for replay
it can be like this

<script>
loadjs.ready("jquery", function() {
//$(document).ready(function(){
$(document).on('click','.add',function(){
alert("hello");
var html='';
html+='<tr>';
html+='<td><input type="text"name="item_name[]" /></td>';
html+='<td><input type="text"name="item_name1[]" /></td>';
html+='<td><select name="accg[]"><option value="">select accoungroup</option><?php  echo fill_unit_select_box();?></select></td>';
html+='<td><button type="button"name="remove"><span >-</span></button></td></tr>';
$('#item_table').append(html);
});
//});
});
</script>

Post Reply