How to use if statments to run second function Google script - if-statement

I am trying to speed up my script, right now I currently have it set up so that on a button click a custom dialog (HTML) appears asking some questions. On submit, it calls out a gs function to pull the info back as variables. Depending on the first answer I have a series of If statments that trigger. Each of them pull up a different template, make a copy, populate some cells, emails it to you, and then dumps the data into a tracker. Each of them are different so the script is rather long - is there a way to have each if statment its own function? Would this even help the speed? I am new to scripting so any feedback is appreciated. Below is the Code and HTML
function onOpen() //adds option to top row in case buttons are not working.
{
var ui = SpreadsheetApp.getUi();
ui.createMenu('Create Doc.')
.addItem('Create Tracked Document', 'addItem')
.addToUi();
}
function addItem()//starts the initiation process
{
var html = HtmlService.createTemplateFromFile('form')
.evaluate()
.setWidth(300)
.setHeight(550);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Create New Document');
}
function addNewItem(form_data)//pulls data from form
{
var ui = SpreadsheetApp.getUi();
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var n = new Date();
var now = ((n.getMonth()+1) + "/" + n.getDate() + "/" + n.getFullYear());
var doctyp = form_data.Document_Type;
var name = form_data.Name;
var title = form_data.Title;
var platform = form_data.Platform;
var area = form_data.Area;
var rota = form_data.Rotation;
var works = form_data.WorkSt;
var recipient = Session.getEffectiveUser().getEmail();
if (form_data.Document_Type == "Text2"){
var dumpfolder = DriveApp.getFolderById("12345")
var templateSheet = DriveApp.getFileById("67890");
var Newform2= templateSheet.makeCopy(title+ " "+now,dumpfolder);
var qs = SpreadsheetApp.open(Newform2);
var dropSheet = qs.getSheetByName("blank");
var URL3 = Newform2.getUrl();
dropSheet.getRange("i8").setValue(title);
dropSheet.getRange("bc5").setValue(now);
dropSheet.getRange("b5").setValue(platform);
dropSheet.getRange("p5").setValue(area);
dropSheet.getRange("x5").setValue(rota);
dropSheet.getRange("al5").setValue(works);
dropSheet.getRange("at6").setValue(name);
NewOPLPOA.setSharing(DriveApp.Access.DOMAIN,DriveApp.Permission.COMMENT);
NewOPLPOA.setOwner("ME");
sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL3]);
GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL3);
ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
" + URL3, ui.ButtonSet.OK);
}
else if (form_data.Document_Type == "Text1"){
var dumpfolder = DriveApp.getFolderById("abcd")
var templateSheet = DriveApp.getFileById("bgtrd");
var Newform1 = templateSheet.makeCopy(title+ " "+now,dumpfolder);
var qs = SpreadsheetApp.open(Newform1);
var dropSheet = qs.getSheetByName("DOC1");
var URL4 = Newform1.getUrl();
dropSheet.getRange("aa3").setValue(platform);
dropSheet.getRange("ah3").setValue(area);
dropSheet.getRange("ao3").setValue(works);
NewSEWO.setSharing(DriveApp.Access.DOMAIN, DriveApp.Permission.COMMENT);
NewSEWO.setOwner("Me");
sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL4]);
GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL4);
ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
" + URL4, ui.ButtonSet.OK);
}
else{
ui.alert("Error, Please try again, make sure you are listing all required information.");
}
}
--HTML--
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body>
<form id="myform">
<div class="form-group">
<label for="Document_Type">Document Type</label>
<select class="form-control" id="Document_Type" name = "Document_Type" required="required">
<?
var SS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Set Up");
var Avals = SS.getRange("A2:A").getValues();
var numberOfValues = Avals.filter(String).length;
var RangeVals = SS.getRange(2,1,numberOfValues).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeVals.length; ++i) { ?>
<option><?!= RangeVals[i] ?></option>
<? } ?>
</select>
</div>
<div class="form-group">
<label for ="Name">Your Name</label>
<select class="form-control" name='Name' id="Name" required="required">
<?
var AvalN = SS.getRange("E2:E").getValues();
var numberOfValuesN = AvalN.filter(String).length;
var RangeValsN = SS.getRange(2,5,numberOfValuesN).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsN.length; ++i) { ?>
<option><?!= RangeValsN[i] ?></option>
<? } ?>
</select>
</div>
<div class="form-group">
<label for="Platform">Platform</label>
<select class="form-control" id="Platform" name = "Platform" required="required">
<?
var AvalP = SS.getRange("C2:C").getValues();
var numberOfValuesP = AvalP.filter(String).length;
var RangeValsP = SS.getRange(2,3,numberOfValuesP).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsP.length; ++i) { ?>
<option><?!= RangeValsP[i] ?></option>
<? } ?>
</select>
</div>
<div class="form-group">
<label for="Area">Area</label>
<select class="form-control" id="Area" name = "Area" required="required">
<?
var AvalA = SS.getRange("D2:D").getValues();
var numberOfValuesA = AvalA.filter(String).length;
var RangeValsA = SS.getRange(2,4,numberOfValuesA).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsA.length; ++i) { ?>
<option><?!= RangeValsA[i] ?></option>
<? } ?>
</select>
</div>
<div class="block form-group">
<label for="Rotation">Rotation</label>
<select class="form-control" name='Rotation' id="Rotation">
<?
var AvalR = SS.getRange("F2:F").getValues();
var numberOfValuesR = AvalR.filter(String).length;
var RangeValsR = SS.getRange(2,6,numberOfValuesR).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsR.length; ++i) { ?>
<option><?!= RangeValsR[i] ?></option>
<? } ?>
</select>
</div>
<div class="block form-group">
<label for="WorkSt">Work Station</label>
<input type='text' name='WorkSt' id="WorkSt" />
</div>
<div class="block form-group">
<label for="Title">Title</label>
<input type='text' name='Title' id="Title" required="required"/>
</div>
<div class="block">
<button type="submit" class="action">Submit</button>
</div>
</form>
<script>
document.querySelector("#myform").addEventListener("submit",
function(e)
{
e.preventDefault(); //stop form from submitting
google.script.run.addNewItem(this);
google.script.host.close();//close this dialogbox
}
);
</script>
</body>
</html>

is there a way to have each if statement its own function?
For visibility purposes, you certainly can modify your code as
function addNewItem(form_data)//pulls data from form
{
var ui = SpreadsheetApp.getUi();
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var n = new Date();
var now = ((n.getMonth()+1) + "/" + n.getDate() + "/" + n.getFullYear());
var doctyp = form_data.Document_Type;
var name = form_data.Name;
var title = form_data.Title;
var platform = form_data.Platform;
var area = form_data.Area;
var rota = form_data.Rotation;
var works = form_data.WorkSt;
var recipient = Session.getEffectiveUser().getEmail();
if (form_data.Document_Type == "Text2"){
function1();
}
else if (form_data.Document_Type == "Text1"){
function2();
}
else{
ui.alert("Error, Please try again, make sure you are listing all required information.");
}
function function1(){
var dumpfolder = DriveApp.getFolderById("12345")
var templateSheet = DriveApp.getFileById("67890");
...
}
function function2(){
var dumpfolder = DriveApp.getFolderById("abcd")
...
}
Would this even help the speed?
Not really. To help up speed, you should rather try to implement Best Practices.
In particular: Reduce repeated calls to external services, including SpreadsheetApp.
For example, try to position the cells to which you want to assign values into an adjacent range, so you can use the method setValues() instead of multiple setValue() and thus make your code more efficient.
Sample:
var range = dropSheet.getRange("I8:N8");
var values = [];
values[0] = [];
values[0].push(title, now, platform, area, rota, works, name);
range.setValues(values);
Also, try to avoid repeating the same request for each if condition and rather make a single request after exiting the if statement, e.g. for:
sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL3]);
GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL3);
ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
" + URL3, ui.ButtonSet.OK);
I hope this helps!

Related

Dynamic options not showing up after adding Chosen

Initially I had everything working with Chosen plugin when the options were directly passed from python to the html template.
I then tried to make the options filled dynamically depending on one of the buttons clicked, the options were not rendered so nothing showed up (but if I inspect the Elements, each optgroup was filled correctly with options).
And if I remove $(".chosen-select").chosen() , then the options are rendered.
Here's my code:
<!-- language: html -->
<div class="container" style="margin:auto; padding-top: 2%; text-align: center;">
<b>Choose the Program:</b>
<ul id="programs" class="no-bullets" data-tag="programList">
<li onclick="selectProgram(this)">Type1</li>
<li onclick="selectProgram(this)">Type2</li>
<li onclick="selectProgram(this)">Type3</li>
</ul>
<b>Choose the Documents:</b>
<select id="documentOptions" name="documents" data-placeholder="Your Documents" class="chosen-select" multiple>
<optgroup label="Group1" id="Group1"></optgroup>
<optgroup label="Group2" id="Group2"></optgroup>
<optgroup label="Group3" id="Group3"></optgroup>
</select>
</div>
<!-- language: lang-js -->
<script>
$(".chosen-select").chosen()
function selectProgram(el){
Array.prototype.slice.call(document.querySelectorAll('ul[data-tag="programList"] li')).forEach(function(element){
element.classList.remove('selected');
});
el.classList.add('selected');
programSelected = el.innerText;
//console.log(programSelected);
fetch(`/api/data/get_program/${programSelected}`)
.then(function(response){
return response.json();
}).then(function(documentList){
documentListJSON = {"documents":documentList};
//console.log(documentListJSON);
$.ajax({
type: 'POST',
url: '/api/data/programDocuments',
contentType: 'application/json',
data: JSON.stringify(documentListJSON),
success: function( allDocuments ){
console.log(allDocuments);
const Type1_Options = document.getElementById("Group1");
const Type2_Options = document.getElementById("Group2");
const Type3_Options = document.getElementById("Group3");
Type1_Options.innerHTML = "";
Type2_Options.innerHTML = "";
Type3_Options.innerHTML = "";
let docs_type1 = allDocuments['type1'];
let docs_type2 = allDocuments['type2'];
let docs_type3 = allDocuments['type3'];
// create list of options
var options = "";
for(var i = 0; i<docs_type1.length;i++){
options += "<option value='" + docs_type1[i] +"'>" + docs_type1[i] + "</option>";
}
Type1_Options.innerHTML += options;
$(Type1_Options).appendTo('#Group1');
var options = "";
for(var i = 0; i<docs_type2.length;i++){
options += "<option value='" + docs_type2[i] +"'>" + docs_type2[i] + "</option>";
}
Type2_Options.innerHTML += options;
$(Type2_Options).appendTo('#Group2');
var options = "";
for(var i = 0; i<docs_type3.length;i++){
options += "<option value='" + docs_type3[i] +"'>" + docs_type3[i] + "</option>";
}
Type3_Options.innerHTML += options;
$(Type3_Options).appendTo('#Group3');
}
})
})
}
</script>
I'm quite new to JavaScript and Jquery..Could someone please help explain why this happens?
Any help is very much appreciated. Thank you!

How to get the ID of record in another html?

why i cant get the ID of payment type, even i already print the ID in the html?
in my first html (elementary.html) I have this code
<select name="gradelevel" id="gradelevel" onchange="ChangeYearList(this.value)">
<option">-- Education Level --</option>
{% for ylvl in edulevel %}
<option value="{{ylvl.id}}">{{ylvl.Description}}</option>
{% endfor %}
</select>
<div id="txtHint" class="scale-in-center" width="100%"></div>
<script>
function ChangeYearList(str) {
var xhttp;
var x = document.getElementById("gradelevel").value;
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
document.getElementById("demo").innerHTML = x;
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xhttp.open("GET", "{% url 'paymentElementary' %}?payments_ID="+str, true);
xhttp.send();
}
</script>
this is my views.py
def paymentElementary(request):
paymentsid = request.GET.get('payments_ID')
payment = ScheduleOfPayment.objects.filter(Education_Levels=paymentsid).order_by('Payment_Type').distinct('Payment_Type')
return render(request, 'accounts/paymentElementary.html', {"payment":payment})
This is my second html (paymentElementary.html)
<select id="payments" name ="payments">
<option value="0">-- Payment Type --</option>
{% for paymentschedule in payment %}
<option value="{{paymentschedule.Payment_Type.id}}">{{paymentschedule.Payment_Type.id}}. {{paymentschedule.Payment_Type}}</option>
{% endfor%}
</select>
this is what it looks like in web view
it works like a charm. but when i tried to save it into my database
id = request.POST.get('payments')
payment = PaymentType(id=id)
V_insert_data = StudentsEnrollmentRecord.objects.create(
Payment_Type=payment
)
this is the error
this is the full traceback
update view.py file in this way
def paymentElementary(request):
paymentsid = request.GET.get('payments_ID')
payment = ScheduleOfPayment.objects.get(Education_Levels=paymentsid).order_by('Payment_Type').distinct('Payment_Type')
return render(request, 'accounts/paymentElementary.html', {"payment":payment})

CF Upgrade Issue while binding dropdown value to a bind in cfgrid

We are upgrading our CF Server 9 to latest CF 2018. And i am facing bind issue between dropdown selected value and cfgrid bind.
There is dropdown just above the cfgrid that is set empty at first and has values listed of a query, and just below is a grid that binds the dropdown selection value to the query that is fetched.
At first as empty is selected it would not fetch records and grid would be empty. Also the bind URL is correctly formed.
http://127.0.0.1:8501/app/dummy.cfm?&DbFunc=getRecords&SrcID=&newSrcID=&flt_nm=&flt_iv=&flt_ct=&flt_sc=&flt_in=&pageSize=174&_cf_ajaxproxytoken=6D89B1BFAE8D17997E5A&_cf_clientid=1AFC4F973849FBAE6EAAA465492A0E0B&_cf_rc=0&_cf_nodebug=true&_cf_nocache=true&returnFormat=json&_dc=1549690631545&start=0&limit=174&page=1&sortCol=&sortDir=ASC
But next when i select the dropdownto a new value the URL is formed in this way.
http://127.0.0.1:8501/app/dummy.cfm?&&DbFunc=getRecords&SrcID=Test&SrcID=&&newSrcID=Test&&flt_nm=&&flt_iv=&&flt_ct=&&flt_sc=&&flt_in=&pageSize=174&_cf_ajaxproxytoken=6D89B1BFAE8D17997E5A&_cf_clientid=1AFC4F973849FBAE6EAAA465492A0E0B&_cf_rc=0&_cf_nodebug=true&_cf_nocache=true&returnFormat=json&_dc=1549690634739&start=0&limit=174&page=1&sortCol=&sortDir=ASC
As you can see the SrcID is getting appended twice for first time empty and next adding the selected value. I am receiving this as a comma separated value on my next page which is incorrect.
the query params are getting added as a separate instead of overwiting the old params.
The SrcID param is defined at top and next is the dropdown and directly at the bottom is the cfgrid where it is used in bind.
Thanks in advance
Here is a sample code below
<cfajaximport tags="cfform, cfinput-datefield, cftooltip, cfwindow, cfgrid, cfmessagebox">
<script type="text/javascript" language="javascript">
function doRefresh(form){
cSrcID = form.SrcID.options[form.SrcID.selectedIndex].value;
console.log('me'+cSrcID+'u');
cSortFld = '';
form.newSrcID.value = cSrcID;
}
// get client area of the browser
var cliWt = getClientWt(); // client width
var cliHt = getClientHt(); // client height
// set grid dimensions scrWidth, scrHeidht
var gWt = 34; // right margin
var gHt = 180; // top margin
var minWt = 500; // min width of the table
var minHt = 280; // min height of the table
var scrWidth = cliWt - gWt;
var scrHeight = cliHt - gHt;
if (scrWidth < minWt) scrWidth = minWt;
if (scrHeight < minHt) scrHeight = minHt;
// set winEdit popup window dimensions
var popwinWt = 1150;
var popwinHt = 680;
var bResizePopup = 0;
if (popwinWt > cliWt) {
bResizePopup = 1;
popwinWt = cliWt - 10;
}
if (popwinHt > cliHt) {
bResizePopup = 1;
popwinHt = cliHt - 10;
}
// set winEdit2 popup window dimensions
var popwinWt2 = 900;
var popwinHt2 = 510;
var bResizePopup2 = 0;
if (popwinWt2 > cliWt) {
bResizePopup2 = 1;
popwinWt2 = cliWt - 10;
}
if (popwinHt2 > cliHt) {
bResizePopup2 = 1;
popwinHt2 = cliHt - 10;
}
// set winEdit3 popup window dimensions
var popwinWt3 = 800;
var popwinHt3 = 550;
var bResizePopup3 = 0;
if (popwinWt3 > cliWt) {
bResizePopup3 = 1;
popwinWt3 = cliWt - 10;
}
if (popwinHt3 > cliHt) {
bResizePopup3 = 1;
popwinHt3 = cliHt - 10;
}
</script>
<cfset maxRowCnt = 174>
<!--- Set Grid default params --->
<cfparam name="page" default="1">
<cfparam name="pageSize" default="#maxRowCnt#">
<cfparam name="cfgridsortcolumn" default="">
<cfparam name="cfgridsortdirection" default="">
<cfform name="mainForm">
<cfoutput>
<br /><cfselect name="SrcID" title="Select a Source" style="width:200px;" onchange="doRefresh(this.form)">
<option value="">Select a Data Source</option>
<option value="Test">Test</option>
</cfselect>
<input type="hidden" name="newSrcID" value="">
<input type="hidden" name="flt_nm" value="" />
<input type="hidden" name="flt_iv" value="" />
<input type="hidden" name="flt_ct" value="" />
<input type="hidden" name="flt_sc" value="" />
<input type="hidden" name="flt_in" value="" />
</cfoutput>
<!--- Main Grid title="List of Records" --->
<cfgrid format="html" name="mainGrid" sort="yes" style="border:1px solid ##002D96;" visible="no" pagesize="#maxRowCnt#" maxrows="#maxRowCnt#" vspace="20"
striperows="yes" striperowcolor="#gcGray#" bgcolor="#gcRowWhite#" colheaderbold="yes" colheadertextcolor="##464646" width="scrWidth" height="scrHeight"
selectcolor="##FFCC99" selectmode="edit" selectonload="false" picturebar="yes" gridlines="yes" autowidth="yes"
bind="url:dummy.cfm?DbFunc=getRecords&SrcID={SrcID}&newSrcID={newSrcID}&flt_nm={flt_nm}&flt_iv={flt_iv}&flt_ct={flt_ct}&flt_sc={flt_sc}&flt_in={flt_in}&page={cfgridpage}&pageSize={cfgridpagesize}&sortCol={cfgridsortcolumn}&sortDir={cfgridsortdirection}"
onchange="url:dummy.cfm?DbFunc=doNothing&action={cfgridaction}&row={cfgridrow}&changed={cfgridchanged}"
font="arial" fontsize="14px" colheaderfont="arial" colheaderfontsize="14px" textcolor="##464646">
<cfgridcolumn name="si_id" header="ID" display="yes" select="no" width="45"/> <!--- FDB-164 --->
</cfgrid>
</cfform>
On the dummy.cfm
returns a query data in JSON format based on the Src Id selected

Ajax dont works populating a form

Hey anyone can help me with this problem ?
I have this issue with my code, two files:
1 - test.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<script>
var url = "getagentids.php?param=";
function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText.split(",");
document.getElementById('formality').value = results[0];
document.getElementById('fullname').value = results[1];
document.getElementById('sex').value = results[2];
document.getElementById('id').value = results[3];
document.getElementById('joindate').value = results[4];
document.getElementById('jobtitle').value = results[5];
document.getElementById('city').value = results[6];
document.getElementById('typeofsalary').value = results[7];
document.getElementById('contract_type').value = results[8];
}
}
function getagentids() {
var idValue = document.getElementById("email").value;
var myRandom=parseInt(Math.random()*99999999); // cache buster
http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject();
</script>
</head>
<body>
<form name="schform">
<table bgcolor="#dddddd">
<tbody>
<?php
echo $param;
include '../../../connect.php';
$db =& JFactory::getDBO();
$query = "SELECT email FROM dbemployeekpw";
$db->setQuery($query);
$result = $db->loadObjectList();
$email = $result[0];
echo " <select size='1' name='email' id='email' onChange='getagentids()' required >
<option value=''> Seleccione </option>";
foreach($result as $email)
{
echo "<option value='".$email->email."'>".$email->email."</option>";
}
echo "</select>"
?>
<tr><td>Formality</td><td><input id="formality" type="text" name="formality"></td></tr>
<tr><td>Fullname</td><td><input id="fullname" type="text" name="fullname"></td></tr>
<tr><td>Sex</td><td><input id="sex" type="text" name="sex"></td></tr>
<tr><td>Id</td><td><input id="id" type="text" name="id"></td></tr>
<tr><td>Joindate</td><td><input id="joindate" type="text" name="joindate"></td></tr>
<tr><td>Jobtitle</td><td><input id="jobtitle" type="text" name="jobtitle"></td></tr>
<tr><td>City</td><td><input id="city" type="text" name="city"></td></tr>
<tr><td>Typesalary</td><td><input id="typeofsalary" type="text" name="typeofsalary"></td></tr>
<tr><td>Contract Type</td><td><input id="contract_type" type="text" name="contract_type"> </td></tr>
<tr><td><input size="60" type="reset" value="Clear"></td><td></td>
</tr>
</tbody></table>
</form>
</body>
</html>
and..
2 - getagentids.php
<?php
//$param = $_GET["param"];
include '../../../connect.php';
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe#kantarworldpanel.com'";
$db->setQuery($query);
$results = $db->loadObjectList();
foreach ( $results as $result )
{
$formality = $result->formality;
$fullname = $result->fullname;
$sex = $result->sex;
$id = $result->id;
$joindate = $result->joindate;
$jobtitle = $result->jobtitle;
$city = $result->city;
$typeofsalary = $result->typeofsalary;
$contract_type = $result->contract_type;
$textout = $formality.",".$fullname.",".$sex.",".$id.",".$joindate.",".$jobtitle.",".$city.",".$typeofsalary.",".$contract_type;
}
echo $textout;
?>
But ajax dont works, only works if I put this :
$query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe#kantarworldpanel.com'";
instead this:
$query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";
But I need that the code works with second one :(
Anyone can help me with this problem ?
Thanks !!
SOLVED (works like a charm!!):
I change this:
$jinput = JFactory::getApplication()->input;
$param = $jinput->get('param', 'param', 'filter');
instead this:
$param = $_GET["param"];
and I'm still with:
$query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";
because this code don't works for me:
$query->select($db->quoteName('*'))
->from($db->quoteName('dbemployeekpw'))
->where($db->quoteName('email') . ' = '. $db->quote($param));
Many Thanks #lodder
Before anything, lets see if the $param variable is correct and gets the value. Add the following which one the form is processed, will display the value. If the result is NULL then you firstly need to ensure you get the correct value. If you do get the correct value, then carry on reading.
Just on a side note, I would recommend looking at the following link rather than using $_GET:
http://docs.joomla.org/Retrieving_request_data_using_JInput
Lets now use up to date coding standards for you database query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('*'))
->from($db->quoteName('dbemployeekpw'))
->where($db->quoteName('email') . ' = '. $db->quote($param));
$db->setQuery($query);
$results = $db->loadObjectList();
Hope this helps

Angularjs filter unordered list

I'm trying to filter strings in a static unordered list. I'm able to filter items in an array but not sure how to do it for static html content.
The way I've learned to achieve it using an array is by using this method:
<input type="search" ng-model="name" />
<ul>
<li ng-repeat="person in people | filter:name">
{{ person }}
</li>
</ul>
I'm trying to achieve the same effect using an existing <ul>
<input type="search" ng-model="filter.name" placeholder="filter..." />
<ul>
<li>Bob/li>
<li>Lisa</li>
<li>Lewis</li>
<li>Xuemin</li>
<li>Tom</li>
<li>Cassidy</li>
</ul>
I want to be able to filter the list items based on the text strings inside them, so for example typing 'L' in the textbox would only show:
Lisa
Lewis
Here is a hacked out way of doing it JSFiddle.
The key to it is in ng-change="filter()". Every time you enter a letter you decide which elements to show or hide.
$scope.filter = function() {
var elem = document.getElementById('list');
for (var i = 0; i < elem.children.length; i++) {
var name = elem.children[i].children[0].innerHTML;
if (name.indexOf($scope.name) != -1 || $scope.name == "") {
elem.children[i].style.display = "block";
} else {
elem.children[i].style.display = "none";
}
}
}
Like I said, it's an ugly hack, but it works. You would be better off making an object out of your names, and using ng-repeat.