use drop down value to run query without submit - sql

<form name = "rsPass" action="<%= pagePath %><%= jspPageName %>.jsp?callrspassthru=true" method="post">
<table cellpadding="0" cellspacing="0" width="640">
<tr>
<td class="wizardHeader" width="100%" style="height: 21px;"> FCAT Scores by Teacher by Course with Gains and Years Growth</td>
</tr>
<tr>
<td class="wizardInstruction" style="padding-top: 10px; padding-right: 30px; padding-left: 30px; height=33px;"valign="top">
<br>
This report will list all teachers, courses, and student's FCAT scores with gains.
<br><br>
</td>
</tr>
<tr>
<td width="100%" height="2" background="images/hr.gif"><IMG height="2" src="images/hr.gif"></td>
</tr>
<table width="700">
<tr>
<td class="detailFormColumn"><br>
<label>Active or Inactive Teachers: </label><br>
<select name="active">
<option value=""> Select <br> </option>
<option value="IS NULL"> Active <br> </option>
<option value="IS NOT NULL">Inactive <br> </option>
</select>
</td>
</tr>
First letter of teacher's last name:
<%
out.println(request.getParameter("active"));
// both of these values are NULL as if they are not being read when the drop down is selected above
Statement db1 = con.createStatement();
int newRecords1 = 0;
SQL1 = " SELECT DISTINCT substring(i.lastName, 1, 1) as grade " +
" FROM employmentAssignment e with(nolock) " +
" JOIN calendar c with(nolock) on c.schoolID = e.schoolID " +
" JOIN person p with(nolock) on p.personID = e.personID " +
" JOIN [identity] i with(nolock) on i.identityID = p.currentIdentityID and i.personID = p.personID " +
" WHERE c.calendarID = " + calID + "" +
" AND e.enddate is " + request.getParameter("active") + "" +
" AND e.teacher = 1 " +
" ORDER BY substring(i.lastName, 1, 1) ";
result1 = db1.executeQuery(SQL1);
out.println("<select name=grade id=15 onchange='loadStudents()'><option value='NULL' selected='true'>Select</option>");
while(result1.next()) { grade=result1.getString(1); out.println("<option value='"+grade+"'>"+grade+"</option>");}
out.println("</select>");
con.close();
%>

Related

Insert multiple records at once from a table

I have this table which is loaded with data from the database and what the user has to do is select the one they want and fill in the data from both the select and the input, and that data can be saved in separate records. It is the first time I work with this so I don't know a bit about the process.
Currently my view I have it this way
<tbody>
#foreach($vsoftware as $cli)
<tr>
<td style="text-align: center;vertical-align: middle">
<input type="checkbox" name="id_software[]" value="{{$cli->id_software}}">
</td>
<td style="text-align: center;vertical-align: middle">{{ $cli->nom_soft}}</td>
<td style="text-align: center;vertical-align: middle">{{ $cli->marca}}</td>
<td style="text-align: center;vertical-align: middle">{{ $cli->nombre_ver}}</td>
<td style="text-align: center;vertical-align: middle">{{ $cli->num_version}}</td>
<td style="text-align: center;vertical-align: middle">
<select class="mr-sm-2" id="inlineFormCustomSelect" name="id_tipo_venta[]" >
<option value="" selected>sale...</option>
<option value="1">Key</option>
<option value="2">Instal</option>
<option value="3">Key + Instal</option>
<option value="3">Viruz</option>
</select>
</td>
<td style="text-align: center;vertical-align: middle">
<input name="obs_software[]" class=" form-control" type="text">
</td>
</tr>
#endforeach
my controller I try to form it like this:
$soft_instal = new Software_instalacion;
$soft_instal->id_instalacion = $instalaciones->id;
$soft_instal->id_historial = $historial->id;
$soft_instal->id_software = $request->id_software;
$soft_instal->id_usuario = $request->id_usuario;
$soft_instal->id_tipo_venta = $request->id_tipo_venta;
$soft_instal->obs_software = $request->obs_software;
dd($soft_instal);
$soft_instal->save();
The answer that the dd gives me is:
response
And the idea is that you can store it like this in the database:
way to save
The simplest way is that you can loop through your checkbox array.
Here check out the #Tim Lewis answer:
submit multiple arrays from html and combine their attribute into seperate collections and store in Laravel App
Also read about Laravel Mass Assignment:
https://laravel.com/docs/8.x/eloquent#mass-assignment
you can use
foreach($request->input('id_software') as $index => $item) {
$soft_instal = new Software_instalacion;
$soft_instal->id_instalacion = $instalaciones->id;
$soft_instal->id_historial = $historial->id;
$soft_instal->id_software = $item;
$soft_instal->id_usuario = $request->input('id_usuario')[$index];
$soft_instal->id_tipo_venta = $request->input('id_tipo_venta')[$index];
$soft_instal->obs_software = $request->input('obs_software')[$index];
$soft_instal->save(); }

I want to add new rows when add button is pressed, and with each added row a delete button should come to delete the row

This is my code in which I have defined a table
<table v-if="Object.keys(content_state).length >= 1" class="editable-table" id="table_value">
<thead>
<tr>
<th class="editable-tabidle-header">Field</th>
<th class="editable-table-header">Value</th>
</tr>
</thead>
<tbody>
<tr v-for="(pageDataItem, idx) in content_state" :key="idx" class="editable-table-row">
<td class="editable-table-data">
<div>{{pageDataItem.modified_keyword}}</div>
</td>
<td class="editable-table-data">
<div>
<b-form-input v-model="pageDataItem.formatted_text" #click="input_form($event)" id= "'pageDataItem.modified_keyword + idx'" :style="{'border': '2px solid rgb(' +
pageDataItem.color[0] + ',' + pageDataItem.color[1] + ',' +
pageDataItem.color[2] + ')', 'border-radius': '4px'}" v-on:dblclick="showModal($event, 0)" plaintext ></b-form-input>
</div>
<b-btn variant="success" #click="Add(id)" id="Add-button">Add</b-btn>
</td>
</tr>
</tbody>
</table>
And Javascript code is
public AddRow(id:any)
{
console.log(id)
var x =1;
let d = document.getElementById(id);
console.log(id)
let clone = d.firstElementChild.cloneNode(true);
clone.value = '';
clone.id= id+x;
this.last_added_row = clone.id;
d.appendChild(clone);
}
How should I add delete button with each new row generated? There should only be one add button per row and as many delete buttons as the input box.

How to send the dictionary data from method to reports foreach loop in odoo 10

I wrote method to print the reports,but I'm getting empty data.Please check the below code and help me.
def birthday_report(self,context=None):
rec = self.env['hr.employee'].search([('birthday','like',date.today().strftime("%____%-%m-%d"))])
print rec,'*************'
data = {}
data['form'] = rec.read(['name', 'birthday', 'work_email','mobile_phone','age'])
print data['form'],"*************************"
return self.env['report'].get_action(rec, 'hr_birthdays.report_contributionregister_birthdays',data=data)
The report code is:
<tbody>
<tr t-foreach="data" t-as="o">
<td class="td-lrbotborder">
<span t-esc="o['name']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['birthday']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['age']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['mobile_phone']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['work_email']" style=" font-size:13px;" />
</td>
</tr>
</tbody>
class TodayBirthdayReport(models.AbstractModel):
_name = 'report.hr_birthdays.report_birthdays'
#api.model
def render_html(self, docids, data=None):
if not data.get('form'):
raise UserError(_("Form content is missing, this report cannot be printed."))
register_ids = self.env.context.get('active_ids', [])
contrib_registers = self.env['hr.employee'].browse(register_ids)
docs = self.env['hr.employee'].browse(self.env.context.get('active_id'))
rec = self.env['hr.employee'].search([('birthday','like',date.today().strftime("%____%-%m-%d"))])
data1 = {}
data1['form'] = rec.read(['name', 'birthday', 'work_email','mobile_phone','age','image_medium'])
lines_data = data1['form']
docargs = {
'doc_ids': register_ids,
'doc_model': 'hr.dashboard',
'docs': contrib_registers,
'data': data,
'lines_data': lines_data,
}
return self.env['report'].render('hr_birthdays.report_birthdays', docargs)

Add rows to a JQuery Datatable

So basically, I get a little bit of idea about using data tables.
However, my question is a bit different based on my requirement. I'm not even sure whether it's possible.
As you may see inside the code, $("#tableContainer tbody").append(productList); basically creates a regular table (NOT a datatable).
Is there a way I can use productList directly inside a datatable so that it is created within the table standards?
$(document).ready(function() {
$.post('query-data.php', {
type: "view-products"
}, function(response) {
var productList;
var parsedResponse = JSON.parse(response);
for (i = 0; i < parsedResponse.length; i++) {
productList = $('<tr><td>' + (parsedResponse[i].IS_AVILABLE == 1 ? '<i class="fa fa-check fa-fw"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>') + '</td><td>' + (parsedResponse[i].IMAGE_URL != "" && parsedResponse[i].IMAGE_URL ? '<i class="fa fa-check fa-fw"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>') + '</td><td>' + parsedResponse[i].PRODUCT_ID + '</td><td>' + parsedResponse[i].NAME + '</td><td>' + parsedResponse[i].CATEGORY_NAME + '</td><td>' + parsedResponse[i].BUSINESS_NAME + '</td></tr>');
$("#tableContainer tbody").append(productList);
}
});
});
<table id="tableContainer" class="table hover view-menus">
<thead>
<tr>
<th>Avail</th>
<th>Img</th>
<th>Prod ID</th>
<th>Prod Name</th>
<th>Cat Name</th>
<th>Biz Name</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Avail</th>
<th>Img</th>
<th>Prod ID</th>
<th>Prod Name</th>
<th>Cat Name</th>
<th>Biz Name</th>
</tr>
</tfoot>
</table>
Whooppie!! Turns out, it was quite simple.
First declare var table = $('table').DataTable(); before starting the for loop.
Then add table.row.add($(productList )).draw(); while iterating, i.e. inside the for loop. DONE! :)
var table = $('table').DataTable();
for (i = 0; i < parsedResponse.length; i++) {
productList = $('<tr><td>' + (parsedResponse[i].IS_AVILABLE == 1 ? '<i class="fa fa-check fa-fw"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>') + '</td><td>' + (parsedResponse[i].IMAGE_URL != "" && parsedResponse[i].IMAGE_URL ? '<i class="fa fa-check fa-fw"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>') + '</td><td>' + parsedResponse[i].PRODUCT_ID + '</td><td>' + parsedResponse[i].NAME + '</td><td>' + parsedResponse[i].CATEGORY_NAME + '</td><td>' + parsedResponse[i].BUSINESS_NAME + '</td></tr>');
table.row.add($(productList)).draw();
}

Append row in table using XAJAX - values are deleted

I have this table in HTML:
<table style="width: 100%;" class="allBorders">
<tbody id="added_articles">
<tr id="header_articles">
<td>test</td>
<td> </td>
</tr>
</tbody>
</table>
And using XAJAX I append new ROW like THIS
function addNewLine()
{
global $objResponse;
$uniqueID = time();
$return = "<tr id='articles_".$uniqueID."'>";
$return .= "<td><input type='text' id='v_$uniqueID' name='v[]' /></td>";
$return .= "</tr>";
$objResponse->append("added_articles", "innerHTML", $return);
return $objResponse;
}
Whenever I add new line all values in previously added lines are cleared..
Example:
1st line is added
value in 1st line is set to "TEST"
2nd line is added and value in 1st line is deleted .. .
Any idea?
<div id="added_articles">
<table style="width: 100%;" class="allBorders">
<tbody>
<tr id="header_articles">
<td>test</td>
<td> </td>`enter code here`
</tr>
</tbody>
</table>
</div>
function addNewLine()
{
global $objResponse;
$return .= "<table style="width: 100%;" class="allBorders">";
$return .= "<tr id='articles_".$uniqueID."'>";
$return .= "<td><input type='text' id='v_$uniqueID' name='v[]' /></td>";
$return .= "</tr></table>";
$objResponse->append("added_articles", "innerHTML", $return);
return $objResponse;
}
I was having a trouble using this function to add 'tr'.
The code that I used was..
function Start($oid){
$objResponse = new xajaxResponse();
$userauth = Authorizer::getUserByID($oid); // I Save here DB rows return.
while ( $rows = $userauth->fetchRow() ){
$row[] = $rows['uid'];
$userInfo = User::userInfo($rows['uid']);
$useradd .= ' <tr class="spaceunder">
<td>'. $rows['uid'] .'</td>
<td>'. $rows['status'] .'</td>
<td>'. $rows['perm'] .'</td>
<td>'. $rows['dtauth'] .'</td>
</tr>';
$objResponse->addAlert($useradd);
$objResponse->addAssign('userAdded', 'innerHTML', $useradd);
return $objResponse->getXML();
}
And my HTML is...
<table id ="userAdded" border="0" cellpadding="0" cellspacing="0" style="width:100%;height:100%;padding:5px 0px 0 0px;margin:0px 0px 0 0px;">
<tr valign="top" style="height:37px;padding:1px 1px 1 1px;margin:0px 0px 0 0px;">
<td align="left">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
</table>
</td>
</tr>
</table>'
And it works perfectly.