I have a function I call to initialize a page :
function initialize_selections() {
var freeamountElement = document.getElementById("text-freeamount");
var dlyElement = document.getElementById("text-dly");
var freeshipperElement = document.getElementById("text-freeshipper");
if(freeamountElement){
var shippingMethod = document.getElementById("text-freeamount").innerText;
document.getElementById('radio-freeamount').checked = true;
document.getElementById('value-shipping').innerHTML = '$0.00';
document.getElementById('text-shipping').innerHTML = shippingMethod;
}else if(dlyElement){
var shippingMethod = document.getElementById("text-dly").innerText;
document.getElementById('radio-dly').checked = true;
document.getElementById('value-shipping').innerHTML = '$0.00';
document.getElementById('text-shipping').innerHTML = shippingMethod;
}else if(freeshipperElement){
var shippingMethod = document.getElementById("text-freeshipper").innerText;
document.getElementById('radio-freeshipper').checked = true;
document.getElementById('value-shipping').innerHTML = '$0.00';
document.getElementById('text-shipping').innerHTML = shippingMethod;
}else{
var shippingMethod = document.getElementById("text-upsxml").innerText;
var shippingValue = document.getElementById("value-upsxml").innerText;
document.getElementById('radio-upsxml').checked = true;
document.getElementById('value-shipping').innerHTML = shippingValue;
document.getElementById('text-shipping').innerHTML = shippingMethod;
}
// myPoints();
};
This is working well on initial page load. Depending on specfic conditions I want to call it again, from a separate function:
function hideForm(){
if (document.getElementById('thebox').checked==true){
document.getElementById('formdiv').style.display="block";
document.getElementById('formdiv2').style.display="none";
document.getElementById('formdiv3').style.display="block";
var shipping_method = 'Pick Up Your Order';
document.getElementById('text-shipping').innerHTML = shipping_method ;
document.getElementById('value-shipping').innerHTML = '$0.00';
document.querySelector('input[name="shipping"]:checked').checked = false;
// myPoints();
} else {
document.getElementById('formdiv').style.display="none";
document.getElementById('formdiv2').style.display="block";
document.getElementById('formdiv3').style.display="none";
var shipping_method = document.getElementById('text-upsxml').innerText;
document.getElementById('text-shipping').innerHTML = shipping_method ;
var shipping_value = document.getElementById('value-upsxml').innerText;
document.getElementById('value-shipping').innerHTML = shipping_value;
document.querySelector('input[name="shipping"]:checked').checked = false;
document.querySelector('input[name="payment"]:checked').checked = false;
initialize_selections();
};
};
Both codes work well and do as I am looking for except that I can not call initialize_selections from hideForm (same thing occurs with the myPoints function, but commented it out to isolate the issue.
Related
Is it possible, depending on the environment of the company, that some features of Google are non-existent? I tried some functions with my personal email and it works; but, in a professional environment it doesn't work.
function getDataForSearch() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName("PEP FORMULAR");
return ws.getRange(6, 1, ws.getLastRow()-1, 6).getValues();
}
var data;
function setDataForSearch(){
google.script.run.withSuccessHandler(function(dataReturned){
data = dataReturned.slice();
}).getDataForSearch();
}
function search(){
var searchInput = document.getElementById("searchInput").value.toString().toLowerCase().trim();
var searchWords = searchInput.split(/\s+/);
//var searchColumns = [0,1,2,3,4,5];
var searchColumns = [0];
//and
var resultsArray = searchInput == "" ? [] : data.filter(function(r){
return searchWords.every(function(word){
return searchColumns.some(function(colIndex){
return r[colIndex].toString().toLowerCase().indexOf(word) != -1;
});
});
});
var searchResultsBox = document.getElementById("searchResults");
var templateBox = document.getElementById("rowTemplate");
var template = templateBox.content;
searchResultsBox.innerHTML = "";
resultsArray.forEach(function(r){
var tr = template.cloneNode(true);
var typeInitiativeColumn = tr.querySelector(".type-initiative");
var pepRefColumn = tr.querySelector(".pep-ref");
var projectNameColumn = tr.querySelector(".project-name");
pepRefColumn.textContent = r[0];
typeInitiativeColumn.textContent = r[2];
projectNameColumn.textContent = r[5];
searchResultsBox.appendChild(tr);
});
}
This code works but, when I try to reproduce it in a professional environment, the function setDataForSerach() is not able to get the data from the function getDataForSearch() and make a copy.
So I've written a bit of code in Actionscript 3.0 that displays a string when you hover over a word on screen. The issue with this however is that when displayed on other devices such as a Windows desktop, the font reverts back to default. I've checked Adobe Animate and my fonts are all embedded correctly in the preferences so I'm assuming something is missing in my code which I've listed here:
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.Font
import com.adobe.tvsdk.mediacore.TextFormat;
stop();
Previous3.addEventListener(MouseEvent.CLICK, Frame4_prev);
function Frame4_prev(event:MouseEvent):void
{
gotoAndStop(3);
}
Next3.addEventListener(MouseEvent.CLICK, Frame4_next);
function Frame4_next(event:MouseEvent):void
{
gotoAndStop(5);
}
/* ---------- HOVER CHART WITH INFO ---------- */
/* MUCH_info (1) */
MUCH_info.addEventListener(MouseEvent.MOUSE_OVER, over1);
MUCH_info.addEventListener(MouseEvent.MOUSE_OUT, out1);
var fl_TF1:TextField;
var textformat1:TextFormat = new TextFormat;
var i1:int = 20;
var fl_TextToDisplay1:String =
"My Utility Cabinet Holdings, LLC";
function over1(event:MouseEvent):void
{
MUCH_info.visible = true;
fl_TF1 = new TextField();
fl_TF1.autoSize = TextFieldAutoSize.LEFT;
fl_TF1.background = false;
fl_TF1.border = false;
fl_TF1.x = 125;
fl_TF1.y = 643;
fl_TF1.text = fl_TextToDisplay1;
addChild(fl_TF1);
textformat1.size = i1;
textformat1.font = "Europa-Regular";
fl_TF1.setTextFormat(textformat1);
}
function out1(event:MouseEvent):void
{
fl_TF1.visible = false;
}
/* RealMTRX_info (2) */
RealMTRX_info.addEventListener(MouseEvent.MOUSE_OVER, over2);
RealMTRX_info.addEventListener(MouseEvent.MOUSE_OUT, out2);
var fl_TF2:TextField;
var textformat2:TextFormat = new TextFormat;
var i2:int = 21;
var fl_TextToDisplay2:String =
"Specializes in tenant billing, sub-metering, and green initiatives";
function over2(event:MouseEvent):void
{
RealMTRX_info.visible = true;
fl_TF2 = new TextField();
fl_TF2.autoSize = TextFieldAutoSize.LEFT;
fl_TF2.background = false;
fl_TF2.border = false;
fl_TF2.x = 125;
fl_TF2.y = 643;
fl_TF2.text = fl_TextToDisplay2;
addChild(fl_TF2);
textformat2.size = i2;
textformat2.font = "Europa-Regular";
fl_TF2.setTextFormat(textformat2);
}
function out2(event:MouseEvent):void
{
fl_TF2.visible = false;
}
/* MUCSaaS_info (3) */
MUCSaaS_info.addEventListener(MouseEvent.MOUSE_OVER, over3);
MUCSaaS_info.addEventListener(MouseEvent.MOUSE_OUT, out3);
var fl_TF3:TextField;
var textformat3:TextFormat = new TextFormat;
var i3:int = 18;
var fl_TextToDisplay3:String =
"An invoice management system able to track, centralize, and analyze billing data";
function over3(event:MouseEvent):void
{
MUCSaaS_info.visible = true;
fl_TF3 = new TextField();
fl_TF3.autoSize = TextFieldAutoSize.LEFT;
fl_TF3.background = false;
fl_TF3.border = false;
fl_TF3.x = 90;
fl_TF3.y = 643;
fl_TF3.text = fl_TextToDisplay3;
addChild(fl_TF3);
textformat3.size = i3;
textformat3.font = "Europa-Regular";
fl_TF3.setTextFormat(textformat3);
}
function out3(event:MouseEvent):void
{
fl_TF3.visible = false;
}
/* MagnaData_info (4) */
MagnaData_info.addEventListener(MouseEvent.MOUSE_OVER, over4);
MagnaData_info.addEventListener(MouseEvent.MOUSE_OUT, out4);
var fl_TF4:TextField;
var textformat4:TextFormat = new TextFormat;
var i4:int = 20;
var fl_TextToDisplay4:String =
"Develops internal system design and updates, robotics, and data mining";
function over4(event:MouseEvent):void
{
MagnaData_info.visible = true;
fl_TF4 = new TextField();
fl_TF4.autoSize = TextFieldAutoSize.LEFT;
fl_TF4.background = false;
fl_TF4.border = false;
fl_TF4.x = 90;
fl_TF4.y = 643;
fl_TF4.text = fl_TextToDisplay4;
addChild(fl_TF4);
textformat4.size = i4;
textformat4.font = "EuropaRegular";
fl_TF4.setTextFormat(textformat4);
}
function out4(event:MouseEvent):void
{
fl_TF4.visible = false;
}
/* GeoMAH_info (5) */
GeoMAH_info.addEventListener(MouseEvent.MOUSE_OVER, over5);
GeoMAH_info.addEventListener(MouseEvent.MOUSE_OUT, out5);
var fl_TF5:TextField;
var textformat5:TextFormat = new TextFormat;
var i5:int = 18;
var fl_TextToDisplay5:String =
"Specializes in data trends and anomalies, cost efficiency, and client consultation";
function over5(event:MouseEvent):void
{
GeoMAH_info.visible = true;
fl_TF5 = new TextField();
fl_TF5.autoSize = TextFieldAutoSize.LEFT;
fl_TF5.background = false;
fl_TF5.border = false;
fl_TF5.x = 90;
fl_TF5.y = 643;
fl_TF5.text = fl_TextToDisplay5;
addChild(fl_TF5);
textformat5.size = i5;
textformat5.font = "EuropaRegular";
fl_TF5.setTextFormat(textformat5);
}
function out5(event:MouseEvent):void
{
fl_TF5.visible = false;
}
/* SST_info (6) */
SST_info.addEventListener(MouseEvent.MOUSE_OVER, over6);
SST_info.addEventListener(MouseEvent.MOUSE_OUT, out6);
var fl_TF6:TextField;
var textformat6:TextFormat = new TextFormat;
var i6:int = 20;
var fl_TextToDisplay6:String =
"Outside services that help maintain the MUC website";
function over6(event:MouseEvent):void
{
SST_info.visible = true;
fl_TF6 = new TextField();
fl_TF6.autoSize = TextFieldAutoSize.LEFT;
fl_TF6.background = false;
fl_TF6.border = false;
fl_TF6.x = 100;
fl_TF6.y = 643;
fl_TF6.text = fl_TextToDisplay6;
addChild(fl_TF6);
textformat6.size = i6;
textformat6.font = "Europa-Regular";
fl_TF6.setTextFormat(textformat6);
}
function out6(event:MouseEvent):void
{
fl_TF6.visible = false;
}
/* Tamara_info (7) */
Tamara_info.addEventListener(MouseEvent.MOUSE_OVER, over7);
Tamara_info.addEventListener(MouseEvent.MOUSE_OUT, out7);
var fl_TF7:TextField;
var textformat7:TextFormat = new TextFormat;
var i7:int = 20;
var fl_TextToDisplay7:String =
"Tamara Naser, President";
function over7(event:MouseEvent):void
{
Tamara_info.visible = true;
fl_TF7 = new TextField();
fl_TF7.autoSize = TextFieldAutoSize.LEFT;
fl_TF7.background = false;
fl_TF7.border = false;
fl_TF7.x = 125;
fl_TF7.y = 643;
fl_TF7.text = fl_TextToDisplay7;
addChild(fl_TF7);
textformat7.size = i7;
textformat7.font = "Europa-Regular";
fl_TF7.setTextFormat(textformat7);
}
function out7(event:MouseEvent):void
{
fl_TF7.visible = false;
}
/* DataEntry_info (8) */
DataEntry_info.addEventListener(MouseEvent.MOUSE_OVER, over8);
DataEntry_info.addEventListener(MouseEvent.MOUSE_OUT, out8);
var fl_TF8:TextField;
var textformat8:TextFormat = new TextFormat ();
var i8:int = 20;
var fl_TextToDisplay8:String =
"Acquires, manages, and enters client invoice data";
function over8(event:MouseEvent):void
{
DataEntry_info.visible = true;
fl_TF8 = new TextField();
fl_TF8.autoSize = TextFieldAutoSize.LEFT;
fl_TF8.background = false;
fl_TF8.border = false;
fl_TF8.x = 100;
fl_TF8.y = 643;
fl_TF8.text = fl_TextToDisplay8;
addChild(fl_TF8);
textformat8.size = i8;
textformat8.font = "Europa-Regular";
fl_TF8.setTextFormat(textformat8);
}
function out8(event:MouseEvent):void
{
fl_TF8.visible = false;
}
/* Control_info (9) */
Control_info.addEventListener(MouseEvent.MOUSE_OVER, over9);
Control_info.addEventListener(MouseEvent.MOUSE_OUT, out9);
var fl_TF9:TextField;
var textformat9:TextFormat = new TextFormat;
var i9:int = 20;
var fl_TextToDisplay9:String =
"Ensures the integrity and quality of data";
function over9(event:MouseEvent):void
{
Control_info.visible = true;
fl_TF9 = new TextField();
fl_TF9.autoSize = TextFieldAutoSize.LEFT;
fl_TF9.background = false;
fl_TF9.border = false;
fl_TF9.x = 100;
fl_TF9.y = 643;
fl_TF9.text = fl_TextToDisplay9;
addChild(fl_TF9);
textformat9.size = i9;
textformat9.font = "Europa-Regular";
fl_TF9.setTextFormat(textformat9);
}
function out9(event:MouseEvent):void
{
fl_TF9.visible = false;
}
/* Finance_info (10) */
Finance_info.addEventListener(MouseEvent.MOUSE_OVER, over10);
Finance_info.addEventListener(MouseEvent.MOUSE_OUT, out10);
var fl_TF10:TextField;
var textformat10:TextFormat = new TextFormat;
var i10:int = 19;
var fl_TextToDisplay10:String =
"Assesses, monitors, and plans the utilization of cash and financial services";
function over10(event:MouseEvent):void
{
Finance_info.visible = true;
fl_TF10 = new TextField();
fl_TF10.autoSize = TextFieldAutoSize.LEFT;
fl_TF10.background = false;
fl_TF10.border = false;
fl_TF10.x = 90;
fl_TF10.y = 643;
fl_TF10.text = fl_TextToDisplay10;
addChild(fl_TF10);
textformat10.size = i10;
textformat10.font = "Europa-Regular";
fl_TF10.setTextFormat(textformat10);
}
function out10(event:MouseEvent):void
{
fl_TF10.visible = false;
}
/* Admin_info (11) */
Admin_info.addEventListener(MouseEvent.MOUSE_OVER, over11);
Admin_info.addEventListener(MouseEvent.MOUSE_OUT, out11);
var fl_TF11:TextField;
var textformat11:TextFormat = new TextFormat;
var i11:int = 20;
var fl_TextToDisplay11:String =
"Acquires and manages physical invoices and handles other projects";
function over11(event:MouseEvent):void
{
HR_info.visible = true;
fl_TF11 = new TextField();
fl_TF11.autoSize = TextFieldAutoSize.LEFT;
fl_TF11.background = false;
fl_TF11.border = false;
fl_TF11.x = 100;
fl_TF11.y = 643;
fl_TF11.text = fl_TextToDisplay11;
addChild(fl_TF11);
textformat11.size = i11;
textformat11.font = "Europa-Regular";
fl_TF11.setTextFormat(textformat11);
}
function out11(event:MouseEvent):void
{
fl_TF11.visible = false;
}
/* HR_info (12) */
HR_info.addEventListener(MouseEvent.MOUSE_OVER, over12);
HR_info.addEventListener(MouseEvent.MOUSE_OUT, out12);
var fl_TF12:TextField;
var textformat12:TextFormat = new TextFormat;
var i12:int = 20;
var fl_TextToDisplay12:String =
"Manages hiring and onboarding of employees and employee relations";
function over12(event:MouseEvent):void
{
HR_info.visible = true;
fl_TF12 = new TextField();
fl_TF12.autoSize = TextFieldAutoSize.LEFT;
fl_TF12.background = false;
fl_TF12.border = false;
fl_TF12.x = 100;
fl_TF12.y = 643;
fl_TF12.text = fl_TextToDisplay12;
addChild(fl_TF12);
textformat12.size = i12;
textformat12.font = "Europa-Regular";
fl_TF12.setTextFormat(textformat12);
}
function out12(event:MouseEvent):void
{
fl_TF12.visible = false;
}
My end goal is to have the string that is displayed on the hover to display with the font Europa Regular. Is this because the string isn't targeted? Any help is greatly appreciated!
if you embedded correctly in the preferences, you should set embedFonts properties true
fl_TF12.embedFonts = true
also you can change your embedded font with this script
fl_TF12.font = Font.enumerateFonts()[0].fontName;
I have a code sample where I want to read some data from input fields and write that data to a different div.
In first section the code works properly, but in 2nd section the value is not shown. I used the alert function to check that wether value is received or not. The value is received but not shown.
What is wrong with my code? (below)
function preview() {
$(".preview_block").fadeIn(1000);
$("body").css("overflow","hidden");
$(".preview_block").css("overflow","auto");
/*======================Value fetch for personal details=======================*/
var fastname1 = document.forms["myform"]["fastname"].value;
if(fastname1==""){fastname1="---null---"}
var lastname1 = document.forms["myform"]["lastname"].value;
if(lastname1==""){lastname1="---null---"}
var sex1 = document.forms["myform"]["radio"].value;
if(sex1==""){sex1="---null---"}
var clgid1 = document.forms["myform"]["clgid"].value;
if(clgid1==""){clgid1="---null---"}
var dob1 = document.forms["myform"]["dob"].value;
if(dob1==""){dob1="---null---"}
var fname1 = document.forms["myform"]["fname"].value;
if(fname1==""){fname1="---null---"}
var mname1 = document.forms["myform"]["mname"].value;
if(mname1==""){mname1="---null---"}
var gname1 = document.forms["myform"]["gname"].value;
if(gname1==""){gname1="---null---"}
var mobno1 = document.forms["myform"]["mobno"].value;
if(mobno1==""){mobno1="---null---"}
var pmobno1 = document.forms["myform"]["pmobno"].value;
if(pmobno1==""){pmobno1="---null---"}
var mail1 = document.forms["myform"]["mail"].value;
if(mail1==""){mail1="---null---"}
var addr11 = document.forms["myform"]["addr1"].value;
if(addr11==""){addr11="---null---"}
var addr21 = document.forms["myform"]["addr2"].value;
if(addr21==""){addr21="---null---"}
var city1 = document.forms["myform"]["city"].value;
if(city1==""){city1="---null---"}
var state1 = document.forms["myform"]["state"].value;
if(state1==""){state1="---null---"}
var pcode1 = document.forms["myform"]["pcode"].value;
if(pcode1==""){pcode1="---null---"}
var ps1 = document.forms["myform"]["ps"].value;
if(ps1==""){ps1="---null---"}
var po1 = document.forms["myform"]["po"].value;
if(po1==""){po1="---null---"}
var country1 = document.forms["myform"]["country"].value;
if(country1==""){country1="---null---"}
document.getElementById("p1").innerHTML = fastname1;
document.getElementById("p2").innerHTML = lastname1;
document.getElementById("p3").innerHTML = sex1;
document.getElementById("p4").innerHTML = clgid1;
document.getElementById("p5").innerHTML = dob1;
document.getElementById("p6").innerHTML = fname1;
document.getElementById("p7").innerHTML = mname1;
document.getElementById("p8").innerHTML = gname1;
document.getElementById("p9").innerHTML = mobno1;
document.getElementById("p10").innerHTML = pmobno1;
document.getElementById("p11").innerHTML = mail1;
document.getElementById("p12").innerHTML = addr11;
document.getElementById("p13").innerHTML = addr21;
document.getElementById("p14").innerHTML = city1;
document.getElementById("p15").innerHTML = state1;
document.getElementById("p16").innerHTML = pcode1;
document.getElementById("p17").innerHTML = ps1;
document.getElementById("p18").innerHTML = po1;
document.getElementById("p19").innerHTML = country1;
/*======================Value fetch for XII standered details=======================*/
var qualification1 = $('#qualification option:selected').html();
if(qualification1==""){qualification1="---null---"}
var q1_board1 = $('#q1_board option:selected').html();
if(q1_board1==""){q1_board1="---null---"}
var clg_nm1 = document.forms["myform"]["clg_nm"].value;
if(session1==""){session1="---null---"}
var regno1 = document.forms["myform"]["regno"].value;
if(regno1==""){regno1="---null---"}
var yr_reg1 = document.forms["myform"]["yr_reg"].value;
if(yr_reg1==""){yr_reg1="---null---"}
var rollno1 = document.forms["myform"]["rollno"].value;
if(rollno1==""){rollno1="---null---"}
document.getElementById("q1").innerHTML = qualification1;
document.getElementById("q2").innerHTML = q1_board1;
document.getElementById("q3").innerHTML = clg_nm1;
document.getElementById("q4").innerHTML = regno1;
document.getElementById("q5").innerHTML = yr_reg1;
document.getElementById("q6").innerHTML = rollno1;
}
Hello Auto completion is not working well in my application.When we type a name it displays only a blank list[ Screenshots attached ].
Controller Code
public function list_UserByName($letters)
{
if(strpos($letters, ","))
{
$letters1 = explode(",",$letters);
$lecount = count($letters1);
$letters = $letters1[$lecount-1];
}
$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
$response=$this->user_model->getAutoUserList($letters);
}
Model Code
public function getAutoUserList($letters)
{
$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
//AND user_type='C' AND user_status='A'
$query="select * from gm_users where uname Like '%$letters%'";
$result_query =$this->db->query($query);
foreach($result_query->result() as $result)
{
//echo "###".$result."|";
//$pinlevel =$this->functions->get_pinlevel($result->pinLevel);
//echo $result->userId."###".$result->uname." [ ".$pinlevel." ] "."|";
echo $result->userId."###".$result->uname."".$result->address." ".$result->city."|";
}
}
billing.php
<input type="text" autocomplete="off" size="20" name="txtname" id="txtname" onkeyup="ajax_showOptions(this,'getCountriesByLetters',event);" value=""/>
ajax-dynamic-list.js
/************************************************************************************************************
(C) www.dhtmlgoodies.com, April 2006
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
Thank you!
www.dhtmlgoodies.com
Alf Magne Kalleland
************************************************************************************************************/
var ajaxBox_offsetX = 25;
var ajaxBox_offsetY = 5;
var ajax_list_externalFile = site_url+'/catalog/list_UserByName'; // Path to external file
var minimumLettersBeforeLookup = 1; // Number of letters entered before a lookup is performed.
var ajax_list_objects = new Array();
var ajax_list_cachedLists = new Array();
var ajax_list_activeInput = false;
var ajax_list_activeItem;
var ajax_list_optionDivFirstItem = false;
var ajax_list_currentLetters = new Array();
var ajax_optionDiv = false;
var ajax_optionDiv_iframe = false;
var ajax_list_MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)ajax_list_MSIE=true;
var currentListIndex = 0;
function ajax_getTopPos(inputObj)
{
var returnValue = inputObj.offsetTop;
while((inputObj = inputObj.offsetParent) != null){
returnValue += inputObj.offsetTop;
}
return returnValue;
}
function ajax_list_cancelEvent()
{
return false;
}
function ajax_getLeftPos(inputObj)
{
var returnValue = inputObj.offsetLeft;
while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
return returnValue;
}
// Edited
function ajax_option_setValue_bkp(e,inputObj)
{
if(!inputObj)inputObj=this;
var tmpValue = inputObj.innerHTML;
//alert(inputObj.id);
document.getElementById('saleUserId').value=inputObj.id;
if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
if(!tmpValue)tmpValue = inputObj.innerHTML;
val = ajax_list_activeInput.value.split(',');
vals = '';
count = val.length - 1;
for(i=0;i<count;i++)
{
vals = vals + val[i] + ',';
}
ajax_list_activeInput.value = vals + tmpValue;
if(document.getElementById(ajax_list_activeInput.name + '_hidden'))document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id;
ajax_options_hide();
}
function ajax_option_setValue(e,inputObj)
{
if(!inputObj)inputObj=this;
var tmpValue = inputObj.innerHTML;
//alert(inputObj.id);
document.getElementById('saleUserId').value=inputObj.id;
if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
if(!tmpValue)tmpValue = inputObj.innerHTML;
ajax_list_activeInput.value = tmpValue;
if(document.getElementById(ajax_list_activeInput.name + '_hidden'))document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id;
ajax_options_hide();
}
function ajax_options_hide()
{
if(ajax_optionDiv)ajax_optionDiv.style.display='none';
if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='none';
}
function ajax_options_rollOverActiveItem(item,fromKeyBoard)
{
if(ajax_list_activeItem)ajax_list_activeItem.className='optionDiv';
item.className='optionDivSelected';
ajax_list_activeItem = item;
if(fromKeyBoard){
if(ajax_list_activeItem.offsetTop>ajax_optionDiv.offsetHeight){
ajax_optionDiv.scrollTop = ajax_list_activeItem.offsetTop - ajax_optionDiv.offsetHeight + ajax_list_activeItem.offsetHeight + 2 ;
}
if(ajax_list_activeItem.offsetTop<ajax_optionDiv.scrollTop)
{
ajax_optionDiv.scrollTop = 0;
}
}
}
function ajax_option_list_buildList(letters,paramToExternalFile)
{
ajax_optionDiv.innerHTML = '';
ajax_list_activeItem = false;
if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=1){
ajax_options_hide();
return;
}
ajax_list_optionDivFirstItem = false;
var optionsAdded = false;
for(var no=0;no<ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++){
if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue;
optionsAdded = true;
var div = document.createElement('DIV');
var items = ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/###/gi);
if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && ajax_list_activeInput.value == items[0]){
ajax_options_hide();
return;
}
div.innerHTML = items[items.length-1];
div.id = items[0];
div.className='optionDiv';
div.onmouseover = function(){ ajax_options_rollOverActiveItem(this,false) }
div.onclick = ajax_option_setValue;
if(!ajax_list_optionDivFirstItem)ajax_list_optionDivFirstItem = div;
ajax_optionDiv.appendChild(div);
}
if(optionsAdded){
ajax_optionDiv.style.display='block';
if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='';
ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
}
}
function ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,whichIndex)
{
if(whichIndex!=currentListIndex)return;
var letters = inputObj.value;
var content = ajax_list_objects[ajaxIndex].response;
var elements = content.split('|');
//alert(content);
ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements;
ajax_option_list_buildList(letters,paramToExternalFile);
}
function ajax_option_resize(inputObj)
{
ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
if(ajax_optionDiv_iframe){
ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;
}
}
function ajax_showOptions(inputObj,paramToExternalFile,e)
{
document.getElementById('saleUserId').value='';
if(e.keyCode==13 || e.keyCode==9)return;
if(ajax_list_currentLetters[inputObj.name]==inputObj.value)return;
if(!ajax_list_cachedLists[paramToExternalFile])ajax_list_cachedLists[paramToExternalFile] = new Array();
ajax_list_currentLetters[inputObj.name] = inputObj.value;
if(!ajax_optionDiv){
ajax_optionDiv = document.createElement('DIV');
ajax_optionDiv.id = 'ajax_listOfOptions';
document.body.appendChild(ajax_optionDiv);
if(ajax_list_MSIE){
ajax_optionDiv_iframe = document.createElement('IFRAME');
ajax_optionDiv_iframe.border='0';
ajax_optionDiv_iframe.style.width = ajax_optionDiv.clientWidth + 'px';
ajax_optionDiv_iframe.style.height = ajax_optionDiv.clientHeight + 'px';
ajax_optionDiv_iframe.id = 'ajax_listOfOptions_iframe';
document.body.appendChild(ajax_optionDiv_iframe);
}
var allInputs = document.getElementsByTagName('INPUT');
for(var no=0;no<allInputs.length;no++){
if(!allInputs[no].onkeyup)allInputs[no].onfocus = ajax_options_hide;
}
var allSelects = document.getElementsByTagName('SELECT');
for(var no=0;no<allSelects.length;no++){
allSelects[no].onfocus = ajax_options_hide;
}
var oldonkeydown=document.body.onkeydown;
if(typeof oldonkeydown!='function'){
document.body.onkeydown=ajax_option_keyNavigation;
}else{
document.body.onkeydown=function(){
oldonkeydown();
ajax_option_keyNavigation() ;}
}
var oldonresize=document.body.onresize;
if(typeof oldonresize!='function'){
document.body.onresize=function() {ajax_option_resize(inputObj); };
}else{
document.body.onresize=function(){oldonresize();
ajax_option_resize(inputObj) ;}
}
}
if(inputObj.value.length<minimumLettersBeforeLookup){
ajax_options_hide();
return;
}
ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
if(ajax_optionDiv_iframe){
ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;
}
ajax_list_activeInput = inputObj;
ajax_optionDiv.onselectstart = ajax_list_cancelEvent;
currentListIndex++;
if(ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()]){
ajax_option_list_buildList(inputObj.value,paramToExternalFile,currentListIndex);
}else{
var tmpIndex=currentListIndex/1;
ajax_optionDiv.innerHTML = '';
var ajaxIndex = ajax_list_objects.length;
ajax_list_objects[ajaxIndex] = new sack();
var search_key = inputObj.value.replace(" ","+");
//search_key1 = search_key.replace(",",",");
var url = ajax_list_externalFile + '/' +search_key;
ajax_list_objects[ajaxIndex].requestFile = url; // Specifying which file to get
ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,tmpIndex); }; // Specify function that will be executed after file has been found
ajax_list_objects[ajaxIndex].runAJAX(); // Execute AJAX function
}
}
function wordcount(string) {
var a = string.split(/\s+/g); // split the sentence into an array of words
return a.length;
}
function ajax_option_keyNavigation(e)
{
if(document.all)e = event;
if(!ajax_optionDiv)return;
if(ajax_optionDiv.style.display=='none')return;
if(e.keyCode==38){ // Up arrow
if(!ajax_list_activeItem)return;
if(ajax_list_activeItem && !ajax_list_activeItem.previousSibling)return;
ajax_options_rollOverActiveItem(ajax_list_activeItem.previousSibling,true);
}
if(e.keyCode==40){ // Down arrow
if(!ajax_list_activeItem){
ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
}else{
if(!ajax_list_activeItem.nextSibling)return;
ajax_options_rollOverActiveItem(ajax_list_activeItem.nextSibling,true);
}
}
/*if(e.keyCode==13 || e.keyCode==9){ // Enter key or tab key
if(ajax_list_activeItem && ajax_list_activeItem.className=='optionDivSelected')ajax_option_setValue(false,ajax_list_activeItem);
if(e.keyCode==13)return false; else return true;
}
if(e.keyCode==27){ // Escape key
ajax_options_hide();
}*/
}
//document.documentElement.onclick = autoHideList;
function autoHideList(e)
{
if(document.all)e = event;
if (e.target) source = e.target;
else if (e.srcElement) source = e.srcElement;
if (source.nodeType == 3) // defeat Safari bug
source = source.parentNode;
if(source.tagName.toLowerCase()!='input' && source.tagName.toLowerCase()!='textarea')ajax_options_hide();
}
Am a beginner in php as well as Codeigniter
Just echo your data in your controller
change
$response=$this->user_model->getAutoUserList($letters);
To
echo $this->user_model->getAutoUserList($letters);
change
onkeyup="ajax_showOptions(this,'getCountriesByLetters',event);
to
onkeyup="ajax_showOptions(this,'list_UserByName',event);
there is a question on this topic on stackoverflow, but an entire different process.
My Codeigniter autocomplete with ajax
Okay, so I have a button without any Id but when it is clicked it starts a function called buttonClick. This function basically controls a slot machine(poke machine) it's images, winnings etc. Note, some code may not work but please disregard this and imagine it working. But how can I make it so that if the user clicks the play button before this function is finished it won't do anything but will still finish the function it's already doing? Sorry for the inconvenience of not having my full length code in here, but a sample of it.
function buttonClick(){
var pic = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg");
var ex1 = pic[Math.floor(Math.random()*pic.length];
var ex2 = pic[Math.floor(Math.random()*pic.length];
var ex3 = pic[Math.floor(Math.random()*pic.length];
var moveImg = new Array("1.gif","2.gif","3.gif");
var timer = new Array("1000","5000","500","2000");
var time = Math.floor(Math.random()*4);
if (document.getElementById('coins').value > 0){
document.getElementById('coins').value -= 1;
pic[0].src = moveImg[0];
pic[1].src = moveImg[1];
pic[2].src = moveImg[2];
setTimeout(function(){
pic[0].src = ex1;
pic[1].src = ex2;
pic[2].src = ex3;
},timer[time])
}
else{
alert('Error insufficient tokens');
}
}
var in_progress = false;
function buttonClick(){
if(!in_progress){
var pic = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg");
var ex1 = pic[Math.floor(Math.random()*pic.length];
var ex2 = pic[Math.floor(Math.random()*pic.length];
var ex3 = pic[Math.floor(Math.random()*pic.length];
var moveImg = new Array("1.gif","2.gif","3.gif");
var timer = new Array("1000","5000","500","2000");
var time = Math.floor(Math.random()*4);
if (document.getElementById('coins').value > 0){
in_progress = true;
document.getElementById('coins').value -= 1;
pic[0].src = moveImg[0];
pic[1].src = moveImg[1];
pic[2].src = moveImg[2];
setTimeout(function(){
in_progress = false;
pic[0].src = ex1;
pic[1].src = ex2;
pic[2].src = ex3;
},timer[time])
} else {
alert('Error insufficient tokens');
}
}
}
alternatively you can wrap the function in a closure to make the in_progress a private variable.
var buttonClick = (function(){
var in_progress = false;
return function(){
if(!in_progress){
var pic = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg");
var ex1 = pic[Math.floor(Math.random()*pic.length];
var ex2 = pic[Math.floor(Math.random()*pic.length];
var ex3 = pic[Math.floor(Math.random()*pic.length];
var moveImg = new Array("1.gif","2.gif","3.gif");
var timer = new Array("1000","5000","500","2000");
var time = Math.floor(Math.random()*4);
if (document.getElementById('coins').value > 0){
in_progress = true;
document.getElementById('coins').value -= 1;
pic[0].src = moveImg[0];
pic[1].src = moveImg[1];
pic[2].src = moveImg[2];
setTimeout(function(){
in_progress = false;
pic[0].src = ex1;
pic[1].src = ex2;
pic[2].src = ex3;
},timer[time])
} else {
alert('Error insufficient tokens');
}
}
};
})();