how to show and hide field based on radio button - php

i have a radio button question that have yes or no answers . i need to show and hide the next fields depend on the radio button answer , if yes show the field if no keep them hide .
here is my code
<?php
if(form_error('HSC'))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="HSC" class="col-sm-2 control-label">
<?=$this->lang->line("student_have_hs")?>
</label>
<div class="col-sm-3">
<input type="radio" name="HSC" value="Yes">Yes<br> <input type="radio" name="HSC" value="No"> No<br>
</div>
<span class="col-sm-4 control-label">
<?php echo form_error('HSC'); ?>
</span>
</div>
<?php
if(form_error('student_date_of_graduate'))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="student_date_of_graduate" class="col-sm-2 control-label">
<?=$this->lang->line("student_date_of_graduate")?>
</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="student_date_of_graduate" name="student_date_of_graduate" value="<?=set_value('student_date_of_graduate')?>" >
</div>
<span class="col-sm-4 control-label">
<?php echo form_error('student_date_of_graduate'); ?>
</span>
</div>
<?php
if(form_error('schoolname'))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="name_id" class="col-sm-2 control-label">
<?=$this->lang->line("student_schoolname")?>
</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="schoolname" name="schoolname" value="<?=set_value('schoolname')?>" >
</div>
<span class="col-sm-4 control-label">
<?php echo form_error('schoolname'); ?>
</span>
</div>
<?php
if(form_error('specialty'))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="specialty" class="col-sm-2 control-label">
<?=$this->lang->line("student_specialty")?>
</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="specialty" name="specialty" value="<?=set_value('specialty')?>" >
</div>
<span class="col-sm-4 control-label">
<?php echo form_error('specialty'); ?>
</span>
</div>
<?php
if(form_error('average'))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="average" class="col-sm-2 control-label">
<?=$this->lang->line("student_average")?>
</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="average" name="average" value="<?=set_value('average')?>" >
</div>
<span class="col-sm-4 control-label">
<?php echo form_error('average'); ?>
</span>
</div>
any one can help please because i dont have too many experience with javascript

Here is basic example by using javascript:
Radio Buttons:
<input type="radio" name="HSC" value="Yes" onChange="getValue(this)">Yes<br>
<input type="radio" name="HSC" value="No" onChange="getValue(this)"> No<br>
Here, i am using onchange() event for value changes.
Your Div:
<div id="yourfield" style="display:none;">
Hide Me: Place your all four fields here
student_date_of_graduate ,
average ,
schoolname and
specialty
</div>
You need a identifier id="yourfield" for perform changes like show and hide the specific div.
Script:
<script type="text/javascript">
function getValue(x) {
if(x.value == 'No'){
document.getElementById("yourfield").style.display = 'none'; // you need a identifier for changes
}
else{
document.getElementById("yourfield").style.display = 'block'; // you need a identifier for changes
}
}
</script>
Simple javascript function, which only use to show or hide your div according to radio button value.

Use jQuery :
$(document).ready(function() {
$('input[type="radio"]').click(function() {
if($(this).attr('id') == 'your input id') {
$('#div id').show();
}
else {
$('#div id').hide();
}
});
});

Related

getting total value after entering the values in the form and inserting into database using codeigniter

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>

Displaying multiple sql columns in one html column

I have a form with multiple checkboxes which are stored as different columns in a database.
I want to display them as a single column in a webpage, how can I do that?
HTML Form:
<div class="form-group">
<label class="col-md-2 control-label">R-11</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="r11" value="R11">
</div>
<label class="col-md-2 control-label">E-1</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="e1" value="E1">
</div>
<label class="col-md-2 control-label">E-2</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="e2" value="E2">
</div>
<label class="col-md-2 control-label">E-3</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="e3" value="E3">
</div>
<label class="col-md-2 control-label">L-1</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="l1" value="L1">
</div>
<label class="col-md-2 control-label">R-12</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="r12" value="R12">
</div>
<label class="col-md-2 control-label">C-1</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="c1" value="C1">
</div>
<label class="col-md-2 control-label">C-2</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="c2" value="C2">
</div>
<label class="col-md-2 control-label">C-3</label>
<div class="col-md-1">
<input type="checkbox" class="form-control" name="c3" value="C3">
</div>
</div>
PHP Code, generating the rows and columns:
<?php
while($maininfo=mysqli_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$maininfo['run_number']."</td>";
echo "<td>".$maininfo['date']."</td>";
echo "<td>".$maininfo['station']."</td>";
echo "<td>".$maininfo['time_of_call']."</td>";
echo "<td>".$maininfo['onscene']."</td>";
echo "<td>".$maininfo['inservice']."</td>";
echo "<td>".$maininfo['address']."</td>";
echo "<td>".$maininfo['category1']."</td>";
echo "<td>".$maininfo['category2']."</td>";
echo "<td>".$maininfo['info']."</td>";
echo "<td>".$maininfo['shift']."</td>";
echo "<td>".$maininfo['name']."</td>";
echo "<td>".$maininfo['r11']."</td>";
echo "<td>".$maininfo['e1']."</td>";
echo "<td>".$maininfo['e2']."</td>";
echo "<td>".$maininfo['e3']."</td>";
echo "<td>".$maininfo['l1']."</td>";
echo "<td>".$maininfo['r12']."</td>";
echo "<td>".$maininfo['c1']."</td>";
echo "<td>".$maininfo['c2']."</td>";
echo "<td>".$maininfo['c3']."</td>";
echo "</tr>";
}//end while
?>
I would like the table in the website to show all of the r-11 thru c-3 in one column. How can I do that? I have tried merging a couple of them together like:
echo "<td>".$maininfo['r11', 'e1']."</td>";
However, that doesn't work.
This represents the output from one database column:
$maininfo['r11']
This is two:
$maininfo['r11'] . $maininfo['e1']
Wrap those two in an HTML table cell:
"<td>" . $maininfo['r11'] . $maininfo['e1'] . "</td>"
Repeat as necessary for however you want to design the HTML output. Add spaces, separators, more HTML markup, etc.
Basically, the values are still individual things. You simply need to concatenate the output together into the HTML structure you want. It's not up to the database to do this, or the array structure. They have their own jobs to do. It's up to you to build your output strings.
echo "<td>".$maininfo['r11'].$maininfo['e1']."</td>";

highlight whole row div red while error instead of just input field [php codeigniter]

I have a form which is posted via php and if I get a error it highlights only the input field red. What I would like to do or know if there is a way to do is highlight the whole div field which contains the select field and everything and show that this whole div has a error.
Here is my html code.
<div class="form-group">
<div class="<?php if(form_error('fullname')!= null){echo ' has-error';} ?>">
<label class="col-md-4 control-label">
<?php echo lang("full_name"); ?>
</label>
<div class="col-md-8">
<input type="text" name="fullname" class="form-control" value="<?php if (isset($userinfo['Fullname'])) {echo $userinfo['Fullname'];} ?>" placeholder="<?php echo lang(" fullname "); ?>">
</div>
</div>
</div>
Right now it only highlights input field but I want it to highlight the whole div form-group.
Since you are using bootstrap, you could try this. Please change
<div class="form-group">
to
<div class="form-group alert alert-danger">
Try this.
<div class="form-group <?php if(form_error('fullname')!= null){echo ' bg-danger';} ?>">
<div class="<?php if(form_error('fullname')!= null){echo ' has-error';} ?>">
<label class="col-md-4 control-label">
<?php echo lang("full_name"); ?>
</label>
<div class="col-md-8">
<input type="text" name="fullname" class="form-control" value="<?php if (isset($userinfo['Fullname'])) {echo $userinfo['Fullname'];} ?>" placeholder="<?php echo lang(" fullname "); ?>">
</div>
</div>
</div>
What I have done is used, .bg-danger, one of the Bootstrap Contextual Classes based on the same if condition you have to apply the has-error class.

Dynamically generated inputs where not submitted

I have a form which is a bunch of elements. Plus there is a Button that creates Input-Elements dynamically:
$(document).ready(function() {
var counter = 0;
$("#addNewItem").on("click", function() {
counter++;
// The PHP handle to create the elements
$.get('showItem.php?zahl=' + counter ,function(data) {
// Add Items:
$('#newItems').after(data);
//Button zum erzeugen Enablen:
$( "#btn_createItem" ).removeAttr( "disabled" );
})
});
});
The PHP-handle contains this:
<div class="row" style="margin-bottom: 1em;" id="item<? echo $zahl; ?>" >
<div class="col-md-6">
<div class="form-group">
<label for="taskForUser"> Product:</label>
<select class="form-control select2" style="width: 100%;" name="prItem<? echo $zahl; ?>" id="prItem<? echo $zahl; ?>">
<option selected>Please choose...</option>
<? //foreach($stmtPL as $rowPL) {
while($rowPRL = $stmtPRL->fetch(PDO::FETCH_NUM)) {
// Get List from Database: ?>
<option><? echo $rowPRL[1] . " * " . $rowPRL[2] . " * " . $rowPRL[4]; ?></option>
<? } ?>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="name">Count:</label>
<input type="text" class="form-control" id="anzahl<? echo $zahl; ?>" name="anzahl<? echo $zahl; ?>" value="1" maxlength="5">
<div class="help-block with-errors"></div>
</div>
</div> <!-- /col -->
<div class="col-md-3">
<div class="form-group">
<label for="name"> </label><br />
</i>
</div>
</div><!-- /col -->
When I click on the button to submit the form, the dynamically generated fields are not present. I tested it with a simple: "print_r($_POST);"
Only the "hardcoded" fields are listet in the array. What can it be?

JQuery fires upon submitting form

I'm currently creating a page where you can fill in damage claims about damaged cars/goods. You have 3 options (driver/subcontractor/personel) and JQuery is used to show/hide different textboxes according to the selected option.
Here's where it gets tricky. Everything works great until I submit the form. When I do it fires the changeVehicle JQuery-function again and reloads the original value in licensePlate again, even after I altered it in the form. The result being that I get the old variable for my license plate.
Does anyone have an idea why it refires?
My code:
<?php
...
<form id="form" class="form-horizontal" method="post" action="<?php echo $url?>&action=edit<?php echo $edit?>" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="filenr"><?php echo $lng->show("claim_file_nr")?></label>
<div class="controls">
<input type="text" id="filenr" name="filenr" value="<?php echo $file_nr?>" disabled>
<input type="hidden" id="file_nr" name="file_nr" value="<?php echo $file_nr?>" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="damage_type"><?php echo $lng->show("claim_damage_type")?>*</label>
<div class="controls">
<select id="damage_type" name="damage_type" <?php if ($par["id"] != 0) { echo "disabled"; } ?>>
<option value="0" <?php if ($damage_type == 0) echo "selected" ?>><?php echo $lng->show("claim_type_vehicle") ?></option>"
<option value="1" <?php if ($damage_type == 1) echo "selected" ?>><?php echo $lng->show("claim_type_goods") ?></option>"
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="date_damage"><?php echo $lng->show("claim_date_damage"); ?>*</label>
<div class="controls">
<div class="input-append">
<input class="input-small" type="text" id="date_damage" name="date_damage" data-date-format="dd-mm-yyyy" placeholder="dd-mm-yyyy"
value="<?php echo $cfunc->convertDateFromDB(substr($date_damage, 0, 10)) ?>" required>
<span class="add-on"><i class="icon-calendar"></i></span>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="description"><?php echo $lng->show("claim_description")?>*</label>
<div class="controls">
<textarea class="input-xxlarge" rows="4" id="description" name="description" required><?php echo $description;?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="choice"><?php echo $lng->show("claim_choice")?>*</label>
<div class="controls controls-row">
<select id="choice" name="choice" onchange="changeChoice();">
<option value="1" <?php if (isset($driver)&& $driver != 0) echo "selected" ?>><?php echo $lng->show("claim_driver") ?></option>"
<option value="2" <?php if (isset($subcontractor)&& $subcontractor != 0) echo "selected" ?>><?php echo $lng->show("claim_subcontractor") ?></option>"
<option value="3" <?php if ($personel != "") echo "selected" ?>><?php echo $lng->show("claim_personel") ?></option>"
</select>
</div>
</div>
<div id="driver-container" class="control-group">
<label class="control-label" for="driver"><?php echo $lng->show("claim_driver")?>*</label>
<div class="controls controls-row">
<select id="driver" name="driver">
<?php
$result = $db->q("SELECT * FROM ERP_drivers");
foreach ($result as $a) {
if ($driver == $a["driver_id"]) {
echo "<option value=".$a["driver_id"]." selected>".$a["driver_name"]."</option>";
}else{
echo "<option value=".$a["driver_id"].">".$a["driver_name"]."</option>";
}
}
?>
</select>
</div>
</div>
<div id="subcontractor-container" class="control-group">
<label class="control-label" for="subcontractor"><?php echo $lng->show("claim_subcontractor")?>*</label>
<div class="controls controls-row">
<select id="subcontractor" name="subcontractor">
<?php
$subcontractors = $db->q("SELECT r.relatie_id, r.relatie_naam
FROM relaties AS r INNER JOIN relatie_lijsten AS l
ON r.relatie_id = l.relatie_lijst_relatie_id
WHERE l.relatie_lijst_relatieslijst_id = 23");
foreach($subcontractors as $s){
if ($subcontractor == $s["relatie_id"]) {
echo "<option value=\"".$s["relatie_id"]."\" selected>".$s["relatie_naam"]."</option>";
}else{
echo "<option value=\"".$s["relatie_id"]."\">".$s["relatie_naam"]."</option>";
}
}
?>
</select>
</div>
</div>
<div id="personel-container" class="control-group">
<label class="control-label" for="personel"><?php echo $lng->show("claim_personel")?>*</label>
<div class="controls controls-row">
<select id="personel" name="personel">
<?php
$personelList = $db->q("SELECT * FROM `erp_gebruiker` WHERE `actief` =1");
foreach($personelList as $p){
if ($personel == $p["gebruiker_id"]) {
echo "<option value=\"".$p["gebruiker_id"]."\" selected>".$p["naam"]."</option>";
}else{
echo "<option value=\"".$p["gebruiker_id"]."\">".$p["naam"]."</option>";
}
}
?>
</select>
</div>
</div>
<div id="vehicle-container" class="control-group">
<label class="control-label" for="vehicle"><?php echo $lng->show("claim_choice_vehicle")?>*</label>
<div class="controls controls-row">
<select id="vehicle" name="vehicle" onchange="changeVehicle();">
<?php
$result = $db->q("SELECT * FROM ERP_vehicles");
foreach ($result as $v) {
if ($vehicle == $v["vehicle_id"]) {
echo "<option value=".$v["vehicle_id"]." selected>".$v["vehicle_name"]."</option>";
}else{
echo "<option value=".$v["vehicle_id"].">".$v["vehicle_name"]."</option>";
}
}
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="license_plate"><?php echo $lng->show("claim_license_plate")?></label>
<div class="controls">
<input type="text" id="license_plate" name="license_plate" value="<?php echo $license_plate; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="faulty"><?php echo $lng->show("claim_faulty")?></label>
<div class="controls controls-row">
<select id="faulty" name="faulty">
<option value="0" <?php if ($faulty == 0) echo "selected"; ?>><?php echo $clng->show("no")?></option>";
<option value="1" <?php if ($faulty == 1) echo "selected"; ?>><?php echo $clng->show("yes")?></option>";
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="file_insurance"><?php echo $lng->show("claim_insurance_nr")?></label>
<div class="controls">
<input type="text" id="file_insurance" name="file_insurance" value="<?php echo $file_insurance?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="damage_amount"><?php echo $lng->show("claim_damage_amount")?></label>
<div class="controls">
<input type="number" step="0.01" id="damage_amount" name="damage_amount" value="<?php echo $damage_amount?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="exemption"><?php echo $lng->show("claim_exemption")?></label>
<div class="controls">
<input type="number" step="0.01" id="exemption" name="exemption" value="<?php echo $exemption?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="amount_payed"><?php echo $lng->show("claim_amount_payed")?></label>
<div class="controls">
<input type="number" step="0.01" id="amount_payed" name="amount_payed" value="<?php echo $amount_payed?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="status"><?php echo $lng->show("claim_status")?></label>
<div id="choice" class="controls">
<select id="status" name="status">
<option value="1" <?php if ($status == 1) echo "selected"; ?>><?php echo $lng->show("claim_status_handling")?></option>";
<option value="2" <?php if ($status == 2) echo "selected"; ?>><?php echo $lng->show("claim_status_handled")?></option>";
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary"><?php echo $knop?></button>
<button type="button" class="btn" onclick="javascript:location.href='<?php echo $url?>'"><?php echo $clng->show("cancel")?></button>
</div>
</form>
<script>
$(function () {
$("input,select,textarea").not("[type=submit]").jqBootstrapValidation();
changeChoice();
// alert("blablabla");
});
$("#date_damage").datepicker({format:'dd-mm-yyyy'});
function changeChoice() {
var c = $("#choice :selected").val();
if (c == "1") {
$("#driver-container").show();
$("#subcontractor-container").hide();
$("#personel-container").hide();
} else if (c == "2") {
$("#driver-container").hide();
$("#subcontractor-container").show();
$("#personel-container").hide();
} else {
$("#driver-container").hide();
$("#subcontractor-container").hide();
$("#personel-container").show();
}
changeVehicle()
}
function changeVehicle() {
var choice = $("#choice :selected").val();
var vehiclePlate = $("#vehicle :selected").val();
var licensePlate = '<?php if ($par["id"] == 0 ) { echo ""; } else { echo $license_plate; }?>'
if (choice == "1" || choice == "3") {
$("#vehicle-container").show();
$("#license_plate").prop('disabled', true);
showLicense(vehiclePlate);
$("#license_plate").val(data[0]);
} else {
$("#vehicle-container").hide();
$("#license_plate").prop('disabled', false);
//$("#license_plate").val(licensePlate);
}
}
function showLicense(plate) {
$.ajax({
type: 'POST',
url: 'index.php?page=claims&ajax=getplate',
dataType: 'json',
data: { plate: plate },
success: function(data) {
$("#license_plate").val(data[0]);
}
});
}
</script>
Found it. It seemds that some validation-code is the bad guy. Everything works fine when I put this in comment:
<script>
$(function () {
//$("input,select,textarea").not("[type=submit]").jqBootstrapValidation();
changeChoice();
});
...
</script>
I don't really have an idea why, I'm still pretty new with this JavaScript/JQuery stuff, but at least I can find a workaround for the validation that line provided.

Categories