i'm new with angular 5.
I'm trying to populate a form with data from a database.
So far this it hid my form and from the ts side it only shows null.
PHP code:
include ('conexion.php');
$id = $_GET['id'];
$sql = "SELECT * FROM tbl_usuario WHERE id=".$id;
if($con){
if(!$result = mysqli_query($con,$sql)) die();
while($data = mysqli_fetch_assoc($result)){
$arreglo[] = $data;
}
echo json_encode($arreglo);
}else{
die ("error");
}
form.html:(the ngModel i used with or without brackets)
<div class="forms">
<form method="post" *ngFor="let x of datos">
<div class="form-row">
<div class="form-group col-md-4">
<label>Nombre</label>
<input type="text" class="form-control col-10" (ngModel)="x.nombre" name="nombre" value="x.nombre" />
</div>
<div class="form-group col-md-4">
<label>Apellido Paterno</label>
<input type="text" class="form-control col-10" (ngModel)="x.a_paterno" name="a_paterno" value="x.a_paterno" required/>
</div>
<div class="form-group col-md-4">
<label>Apellido Materno</label>
<input type="text" class="form-control col-10" (ngModel)="x.a_materno" name="a_materno" value="x.a_materno" required/>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>Edad</label>
<input type="text" class="form-control col-10" (ngModel)="x.edad" name="edad" value="x.edad" required/>
</div>
<div class="form-group col-md-6">
<label>Carrera</label>
<input type="text" class="form-control col-10" (ngModel)="x.carrera" name="carrera" value="x.carrera" required />
</div>
<div class="col-md-10">
<label>Direccion</label>
<input type="text" class="form-control col-12" (ngModel)="x.direccion" name="direccion" value="x.direccion" required/>
</div>
<div class="col-md-10">
<br>
<label>Telefono</label>
<input type="text" class="form-control col-12" (ngModel)="x.telefono" name="telefono" value="x.telefono" required/>
</div>
</div>
<br>
<button type="submit" class="btn btn-primary">Enviar Datos</button>
<br>
<br>
</form>
</div>
form.ts:
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {
this.mostrarDatos();
}
ngOnInit() {
this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
console.log('Mi id' + this.id);
});
}
mostrarDatos() {
console.log(this.id);
this.http.get('http://localhost/crudu/mostrarID.php?id=' + this.id).subscribe((data) => {
this.datos = data;
console.log(this.datos);
});
}
I've been trying with many solutions but nothing at the end.
Also in my route or url it shows as eUsuario/1
Try to replace (ngModel) with [(ngModel)]. Currently you have a binding from the input into model but not vice versa.
Remove the call of mostrarDatos from the constructor and call it after you get the id.
this.route.params.subscribe(params => {
this.id = params['id']; // (+) converts string 'id' to a number
console.log('Mi id' + this.id);
this.mostrarDatos();
});
Related
i have a problem where the value isn't calculated.
I have function where the user able to update Weight/size and quantity(if the input isn't in readonly). When the user enter a new weight/size it will be auto-calculated in the Order Total. Apparently, there is a value already in the Order Total (since it is an update) so i want it to auto update the value in the order total when the user update the new input in weight/size or quantity.
pls click this picture
here is my updates.blade.php
<div class="col-sm-12 col-md-6" >
<div class="card">
<div class="card-body">
<div class="form-actions">
<div class="container" style="padding: 0;margin: 0;">
<div class="row">
<div class="col-sm-6" >
<span class="float-sm-left">
<h3 class="card-title">Update Order</h3>
</span>
</div>
</div>
</div>
</div>
</br>
<form action="" method="POST" >
#csrf
#method('PUT')
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationTooltip01">Order ID</label>
<input type="text" class="form-control" wire:model="orderID" value="" readonly>
</div>
<div class="col-md-4 mb-3">
<label for="validationTooltip02">Order Date</label>
<input type="text" class="form-control" wire:model="orderDate" value="" readonly>
</div>
<div class="col-md-4 mb-3">
<label for="validationTooltipUsername">Order Status</label>
<input type="text" class="form-control" wire:model="orderStatus" value="" readonly>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label class="form-control-label" >Customer Phone Number</label>
<input type="text" name="" value="" class="form-control" maxlength="11" wire:model="custPhone" readonly>
</div>
<div class="col-md-6 mb-3">
<label class="form-control-label" >Customer Name</label>
<input type="text" name="" value="" class="form-control" maxlength="11" wire:model="custName" readonly>
</div>
</div>
<div class="form-row">
#foreach($serviceOrder as $o)
<div class="col-md-5 mb-3">
<label class="form-control-label" >Service {{ $loop->iteration }} </label>
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.serv.serviceName" class="form-control " readonly>
</div>
<input type="hidden" wire:model="serviceOrder.{{ $loop->index }}.serv.servicePrice" class="form-control col-sm-1 mb-3" readonly>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Weight/Size</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.weightsize" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$serviceOrder[$loop->index]['quantity']) readonly #endif >
</div>
#endforeach
</div>
<label class="form-control-label" >Order Total RM</label>
<input type="number" wire:model="orderTotal" value="" class="form-control" readonly>
</br>
<div class="form-actions">
<div class="container" style="padding: 0;margin: 0;">
<div class="row">
<div class="col-sm-6" >
<span class="float-sm-left">
<a class="btn btn-primary" href="{{ route('orders.indexInProcess') }}"> Back</a>
</span>
</div>
<div class="col-sm-6">
<span class="float-sm-right">
<div class="text-right">
<button type="submit" class="btn btn-info mr-2">Update</button>
<button type="reset" class="btn btn-dark float-right">Reset</button>
</div>
</span>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
here is the livewire updates.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Customer;
use App\Service;
use App\Order;
use App\ServiceOrder;
class Updates extends Component
{
public $orders;
public $orderID;
public $orderDate;
public $orderStatus;
public $orderTotal;
public $custName;
public $custPhone;
public $serviceName;
public $servicePrice;
public $weightsize;
public $quantity;
public $serviceOrder;
public function mount($order,$so)
{
//$orders = Order::with('customer')->get();
//ServiceOrder::with('serv')->where('order_id', $order->id)->get();
$this->orderID = $order->id;
$this->orderDate = $order->orderDate;
$this->orderStatus = $order->orderStatus;
$this->orderTotal = $order->orderTotal;
$this->custPhone = $order->customer->custPhone;
$this->custName = $order->customer->custName;
$this->serviceOrder = $so->toArray();
//dd($this->serviceOrder);
//$so->serviceName,
//$so->weightsize,
//$so->quantity
}
public function render()
{
//$so = ServiceOrder::with('serv')->where('order_id', $order->id)->get();
return view('livewire.updates');
}
public function updatedInputs($name)
{
$array = explode('.', $name);
if ($array[1] == 'serviceName') {
$this->inputs[$array[0]]['servicePrice'] = $this->services->find($value)->servicePrice;
}
try {
$this->calculateTotal();
} catch (\Exception $e) {
}
}
// perform calculation here.
public function calculateTotal(){
$this->orderTotal = $this->orderTotal;
foreach ($this->serviceOrder as $item) {
if($item['quantity'] == ''){
$item['optQuantity']= 1;
$this->orderTotal += ($item['servicePrice'] * $item['weightsize']) * ($item['quantity']);
}else{
$this->orderTotal += $item['servicePrice'] * ($item['weightsize']) * ($item['quantity']);
}
//$this->total *= $item['optQuantity']; // * price;
}
}
}
please help me out here T.T
You can fire event from component (for example) and then register listener in class and call a method for updating total. Check documentation for that.
"Apparently, there is a value already in the Order Total (since it is an update) so i want it to auto update the value in the order total when the user update the new input in weight/size or quantity."
So, the problem is $orderTotal only update once? it doesn't update when user update new input?. Livewire should render everytime there is action or any input.
First of all, i advice u to check what happen when to your function when user update the new input with dd function.
public function calculateTotal(){
dd('is this func work?');
$this->orderTotal = $this->orderTotal;
foreach ($this->serviceOrder as $item) {
if($item['quantity'] == ''){
$item['optQuantity']= 1;
$this->orderTotal += ($item['servicePrice'] * $item['weightsize']) * ($item['quantity']);
}else{
$this->orderTotal += $item['servicePrice'] * ($item['weightsize']) * ($item['quantity']);
}
//$this->total *= $item['optQuantity']; // * price;
}
}
After you debug your function, maybe you already found the answer you looking for or you can come back and ask me anything. ^^
I want only 4 columns from database in below
I have to get only 4 column from database for displaying in textfield please give suggestion for that. The table is shown below thank you
$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row_getnm = $result_getnm->fetch_array())
$util_value_email_data=?
$util_value_mobile_data=?;
$util_value_map_data=?;
$util_value_data=?;
html form
<form id="submitForm" method="post" role="form" name="hl_form" method="post" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label for="mobile_number">Email*</label>
<input class="form-control" id="util_value_email" name="util_value_email" value="<?Php echo $util_value_email_data; ?>" maxlength="250" placeholder="Enter Email Address" type="text">
</div>
<div class="form-group">
<label for="mobile_number">Mobile*</label>
<input class="form-control" id="util_value_mobile" name="util_value_mobile" value="<?Php echo $util_value_mobile_data; ?>" maxlength="250" placeholder="Enter Mobile Number" type="text">
</div>
<div class="form-group">
<label for="mobile_number">Map*</label>
<input class="form-control" id="util_value_map" name="util_value_map" value="<?Php echo $util_value_map_data; ?>" maxlength="250" placeholder="Enter Map Address" type="text">
</div>
<div class="form-group">
<label for="description" class="required">Description*</label>
<textarea class="form-control" style="resize: none;" id="util_value" name="util_value" rows="3" placeholder="Enter Description"><?Php echo $util_value_data; ?></textarea>
</div>
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
Below is the code from which you can get all the four data that you want.
$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row_getnm = $result_getnm->fetch_array()) {
if($row_getnm['util_head'] == 'wc_email'){
$util_value_email_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_contact_us'){
$util_value_contact_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_mobile'){
$util_value_mobile_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_google_map'){
$util_value_map_data = $row_getnm['util_value'];
}
}
You need to replace * with columns name with comma separation.
$sql_getnm = "SELECT Columname1,Columname2,Columname3,Columname4 FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row = mysql_fetch_array($result_getnm, MYSQL_ASSOC)
$util_value_email_data= $row['Columname1'];
$util_value_mobile_data= $row['Columname2'];
$util_value_map_data= $row['Columname3'];
$util_value_data= $row['Columname4'];
Right now I am facing a problem : I am trying to insert records in the database with the help of jQuery & Ajax. Unfortunately, I tried to alert inserted values but It doesn't show. I also checked through serialize function and I am unable to do that.
Here is my code of ajax
<script type="text/javascript">
$(document).ready(function(){
$("#add_new").click(function(){
$("#add").slideToggle();
});
$("#submit").click(function(){
var stud_no=$("#roll").val();
if(stud_no==''){
$("#msg").html("Input Roll Number");
} else {
var datastr = $("#sampleform").serialize();
alert(datastr);
$.ajax({
type:'POST',
url:'add_it.php',
data:datastr,
success:function(response){
$("#my_form")[0].reset();
$("#msg").html("Student Successfully Added");
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
}
});
});
</script>
Here is body code :
<body>
<a id="add_new">+add new item</a><br /><br />
<div id="msg"></div><br />
<div id="add">
<form id="sampleform">
<fieldset>
<div class="form-group row">
<label for="roll" class="col-sm-2 col-form-label">Roll Number</label>
<div class="col-sm-6">
<input type="text" name="roll" class="form-control" id="roll">
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-6">
<input type="text" name="name" class="form-control" id="name">
</div>
</div>
<div class="form-group row">
<label for="clas" class="col-sm-2 col-form-label">Class</label>
<div class="col-sm-6">
<input type="text" name="standard" class="form-control" id="standard">
</div>
</div>
<div class="form-group row">
<label for="mail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-6">
<input type="email" name="mail" class="form-control" id="mail">
</div>
</div>
<button type="submit" id="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</fieldset>
</fieldset>
</form>
</div>
Here is my add_it.php
<?php
include('connectdb.php');
$stud_no = trim($_POST['stud_no']);
$name = trim($_POST['name']);
$standard = trim($_POST['standard']);
$mail = trim($_POST['mail']);
$query = "insert into student (stud_no,name,standard,email) values ('$stud_no','$name','$standard','$mail')";
mysqli_query($con,$query) or die (mysqli_error());
?>
Your HTML form fields doesnt have any of these variables sent. You need to add name="email" etc to your form fields.
So for example the email field has to look like this:
<input type="email" name="email" class="form-control" id="mail">
id, class etc is not sent in POST - and therefor can not be recieved in the other end.
Jquery's serialize() function also only handles "name" fields.
https://api.jquery.com/serialize/
Snippet :
For a form element's value to be included in the serialized string, the element must have a name attribute
So, I have my SPA at about 98% functional. The app pulls data from a MySQL database and allows the user to edit/delete records. For the page in question, it will edit/delete data of the specified student ID but it will not properly display the data in the text fields.
If you do not input a value it will display the first item in the JSON array but not the one you specify in the search field.
I did not do a very good job at explaining that but here is the HTML page that uses a function to pass data to the controller which then selects the corresponding student by ID and assigns it to the variable $scope.student. I then try to display the student data on the HTML page by using student.first_name (or any property) but it does not work correctly.
<h3>Edit/Delete Student with ID: {{student.student_id}}</h3>
<div class="form-group">
<label for="sid">Student ID:</label>
<input type="text" class="form-control" id="sid" ng-model="sid">
</div>
<p><button type="button" class="btn btn-primary" ng-click="getRecord(sid)">
Get Student Info </button> </p>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" ng-model="student.first_name">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" ng-model="student.last_name">
</div>
<div class="form-group">
<label for="hrs_completed">Hrs Completed:</label>
<input type="text" class="form-control" id="hrs_completed" ng-model= "student.hrs_completed">
</div>
<div class="form-group">
<label for="hrs_attempted">Hrs Attempted:</label>
<input type="text" class="form-control" id="hrs_attempted" ng-model= "student.hrs_attempted">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="gpa_points">GPA Points:</label>
<input type="text" class="form-control" id="gpa_points" ng-model= "student.gpa_points">
</div>
<div class="form-group">
<label for="major">Major:</label>
<input type="text" class="form-control" id="major" ng-model="student.major">
</div>
<div class="form-group">
<label for="advisor_id">Advisor ID:</label>
<input type="text" class="form-control" id="advisor_id" ng-model="student.advisor_id">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" id="email" ng-model="student.email">
</div>
</div>
<button type="button" class="btn btn-primary" ng-click="updateRecord()">Update</button>
<button type="button" class="btn btn-primary" ng-click="deleteRecord()">Delete</button>
And here is my controller on my Javascript page:
app.controller('editCtrl', function($scope, $http) {
$http.get("getStudentData.php")
.then(function (response) {
$scope.students = response.data;
});
$scope.getRecord = function(sid) {
id = sid;
$scope.student = $scope.students.find(s=>s.id == sid);
};
Do I need to make a seperate GET request to the server for this to work properly or do I just need to reference the student object differently?
I think there is mismatch in what you are getting as response.data and what you are trying to .find() and then what you are binding on html.
Check this plunkr.
You are trying to render by searching id property.
$scope.students.find(s=>s.id == sid);
where as you are rendering on UI using student_id property.
{{student.student_id}}
So, surely there is mismatch in what you are getting as response.data and what you are rendering using $scope.student properties. I think my plunkr will show that your function is correct.
In case this answer doesn't work, share your response.data.
If i select Local Sales from dorpdown and enter DEF, GHI values then the sum of DEF,GHI should be displayed in total value or if i select Inter State,Stock Transfers from dropdown then if we enter ABC value that value should be displayed in total value or else if we select JOB WORK,EXEMPTED SALES from dropdown then the total value should be displayed as zero. The total value which ever we are getting that should be inserted into database.
Controller:
function addinvoice()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
$this->form_validation->set_rules('user','User');
$this->form_validation->set_rules('freight_charges');
$this->form_validation->set_rules('abc');
$this->form_validation->set_rules('def');
$this->form_validation->set_rules('ghi');
$this->form_validation->set_rules('total');
if($this->form_validation->run()== FALSE)
{
$data['mainpage']='invoice';
$data['mode']='add';
$this->load->view('templates/template',$data);
}
else
{
$this -> invoice_model -> insert();
$this->flash->success('<h2> Details added Successfully!</h2>');
redirect('invoice');
}
}
Model:
function insert()
{
$data['total']=0;
$data['user'] = $this->input->post('user');
$data['ghi'] = ($this->input->post('ghi'))?$this->input->post('ghi'):0;
$data['abc'] = ($this->input->post('abc'))?$this->input->post('abc'):0;
$data['def'] = ($this->input->post('def'))?$this->input->post('def'):0;
$data['total'] = $data['ghi'] + $data['abc'] + $data['def'];
$data['freight_charges'] = $this->input->post('freight_charges');
$this->db->insert('invoice',$data);
}
View:
<script>
function showRequiredOption(cval)
{
if((cval=='interstate') || (cval == "stocktransfers"))
{
$('#ghi').hide();
$('#def').hide();
$('#abc').show();
}
else if ((cval=='exemptedsales') || (cval=="zeroratedsales") ||(cval=="jobwork"))
{
$('#ghi').hide();
$('#def').hide();
$('#abc').hide();
}
else
{
$('#abc').hide();
$('#ghi').show();
$('#def').show();
}
}
</script>
<div class="col-md-9 col-md-offset-2">
<div id="legend">
<legend class="">Profile Information</legend>
</div>
<form role="form" action="<?php echo site_url();?>invoice/addinvoice" method="post" class="form-horizontal" id="location" method="post" accept-charset="utf-8">
<div class="form-group">
<label class="control-label col-sm-2 " for="user">User</label>
<div class="col-sm-4 col-sm-offset-1">
<select id="user" name="user" onchange="showRequiredOption(this.value)">
<option value="employee">Local Sales</option>
<option value="interstate">Inter state</option>
<option value="stocktransfers">Stock transfers</option>
<option value="exemptedsales">Exempted Sales</option>
<option value="zeroratedcompany">Zero Rated Sales</option>
<option value="jobwork">Job Work</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 " for="freight_charges">Freight Charges</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control" id="freight_charges" name="freight_charges" value="<?php echo set_value('freight_charges');?>" />
</div>
</div>
<div class="form-group" id="abc" style="display:none;">
<label class="control-label col-sm-2 " for="abc">ABC</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control" id="abc" name="abc" value="<?php echo set_value('abc');?>"/ >
</div>
</div>
<div class="form-group" id="def">
<label class="control-label col-sm-2 " for="def">DEF </label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control" id="def" name="def" value="<?php echo set_value('def');?>"/ >
</div>
</div>
<div class="form-group" id="ghi">
<label class="control-label col-sm-2 " for="ghi">GHI</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control" id="ghi" name="ghi" value="<?php echo set_value('ghi');?>"/ >
</div>
</div>
<div class="form-group" id="cgst">
<label class="control-label col-sm-2 " for="total">Total</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control" name="total" >
</div>
</div>
<button id="submit" type="submit" class="btn" name="submit">Submit</button>
</form>
</div>
Whatever values i have selected from dropdown only those values to be inserted into database and the rest of the values should be inserted as zero in the database.
Actually i am not getting how to do these can anyone check this.Thanks in Advance.
you should check for posted values in your php code as:
$total = 0;
if($this->input->post('this')){
$total = $this->input->post('this');//value in total
}
if($this->input->post('this2')){
$total += $this->input->post('this2');//value in total
}
and at the end send $total value in db as well.
in short php if else tags you can set variables like;
$this = ($this->input->post('this'))?$this->input->post('this'):0;
$this2 = ($this->input->post('this2'))?$this->input->post('this2'):0;
and then at the end you can make total of them and save them to database. OR as suggested above in comments that make your columns as DEFAULT 0 in your table.
------- IN YOUR CASE------
function insert()
{
$data['total']=0;
$data['user'] = $this->input->post('user');
$data['ghi'] = ($this->input->post('ghi'))?$this->input->post('ghi'):0;
$data['abc'] = ($this->input->post('abc'))?$this->input->post('abc'):0;
$data['def'] = ($this->input->post('def'))?$this->input->post('def'):0;
$data['total'] = $data['ghi'] + $data['abc'] + $data['def'];
$data['freight_charges'] = $this->input->post('freight_charges');
$this->db->insert('invoice',$data);
}
---------------IN JavaScript------------
on your event handler you can sum these by their IDs.
var total = parseInt($('#ghi').val())+parseInt($('#def').val());
and then show this total in your total div
$('#yourTotalDiv').text(total);
Displaying total amount on enter the details.
<script>
function showRequiredOption(cval)
{
if((cval=='interstate') || (cval == "stocktransfers"))
{
$('#ghi').hide();
$('#def').hide();
$('#abc').show();
}
else if ((cval=='exemptedsales') || (cval=="zeroratedsales") || (cval=="jobwork"))
{
$('#ghi').hide();
$('#def').hide();
$('#abc').hide();
}
else
{
$('#abc').hide();
$('#ghi').show();
$('#def').show();
}
}
</script>
<script>
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$(".txt").each(function() {
$(this).keyup(function(){
calculateSum();
});
});
});
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".txt").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#sum").html(sum.toFixed(2));
}
</script>
<div class="col-md-9 col-md-offset-2">
<div id="legend">
<legend class="">Profile Information</legend>
</div>
<form role="form" action="<?php echo site_url();?>invoice/addinvoice" method="post" class="form-horizontal" id="location" method="post" accept-charset="utf-8">
<div class="form-group">
<label class="control-label col-sm-2 " for="user">User</label>
<div class="col-sm-4 col-sm-offset-1">
<select id="user" name="user" onchange="showRequiredOption(this.value)">
<option value="employee">Local Sales</option>
<option value="interstate">Inter state</option>
<option value="stocktransfers">Stock transfers</option>
<option value="exemptedsales">Exempted Sales</option>
<option value="zeroratedcompany">Zero Rated Sales</option>
<option value="jobwork">Job Work</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 " for="freight_charges">Freight Charges</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control txt" id="freight_charges" name="freight_charges" value="<?php echo set_value('freight_charges');?>" />
</div>
</div>
<div class="form-group" id="abc" style="display:none;">
<label class="control-label col-sm-2 " for="abc">ABC</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control txt" id="abc" name="abc" value="<?php echo set_value('abc');?>"/ >
</div>
</div>
<div class="form-group" id="def">
<label class="control-label col-sm-2 " for="def">DEF </label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control txt" id="def" name="def" value="<?php echo set_value('def');?>"/ >
</div>
</div>
<div class="form-group" id="ghi">
<label class="control-label col-sm-2 " for="ghi">GHI</label>
<div class="col-sm-4 col-sm-offset-1">
<input type="text" class="form-control txt" id="ghi" name="ghi" value="<?php echo set_value('ghi');?>"/ >
</div>
</div>
<div class="form-group" id="summation">
<label class="control-label col-sm-2 " for="total">Total</label>
<div class="col-sm-4 col-sm-offset-1">
<span id="sum" class="form-control" type="text" name="total">0</span>
</div>
</div>
<button id="submit" type="submit" class="btn" name="submit">Submit</button>
</form>
</div>