So I'm attempting to run a webpage that shows security camera feeds for a client. However it does not render properly at all and only shows the background. I have a feeling it has to do with a limitation of the iframe tag, since using other iframe testing gadgets online I get the same results. Other clients are using camera feeds with a different interface and my solution works fine for them. Are there any alternatives to iframe?
edit: The page actually renders perfectly fine when being visited directly, and not through an iframe.
edit2: By popular request here is the source for the security feed site. I did not post my iframe code, since no matter what I use for iframe it will not display.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="expires" content="-1">
<title>:::</title>
<script language="JavaScript" src="/js/lgSource.js"></script>
<script language="JavaScript" src="/js/data_init.js"></script>
<script language="javascript" src="/js/AVUtility.js"></script>
<script language="JavaScript">
var d = document ;
d.write( "<frameset frameSpacing=0 rows='37,*' frameBorder='no' >" ) ;
d.write( " <frame name='ban' src='' scrolling='no'>" ) ;
d.write( " <frameset frameSpacing=0 frameBorder='no' cols='*,195'>" ) ;
d.write( " <frame name='main' src='home.htm' scrolling='auto'>" ) ;
d.write( " <frame name='left' src='' noResize scrolling='no'>" ) ;
d.write( " </frameset>" ) ;
d.write( "</frameset>" ) ;
d.write( "<noframes><body><p>no frame</p></body></noframes>" ) ;
var httpObj,httpObj2,httpObj3;
//alert("Code in NFS. H264 \n\n charset=utf-8");
//top.dt.user.SupportLG = "ENGLISH&CHINESE&"
loadSupportLanguage();
//loadUserPwd();
function loadSupportLanguage()
{
httpObj3 = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/nobody/Machine.cgi?action=get_capability";
httpObj3.onreadystatechange = updSL;
requestCgiParam(httpObj3, requestData);
}
function updSL()
{
if (httpObj3.readyState == 4 && httpObj3.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj3.responseText;
if (GetCgiParam(objStr,"Language.Support=") == 1)
if (objStr.strGet != "")
top.dt.user.SupportLG = objStr.strGet;
loadUserPwd();
}
}
function loadUserPwd()
{
httpObj = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/guest/UserInfo.cgi?action=query";
httpObj.onreadystatechange = updUserPwd;
requestCgiParam(httpObj, requestData);
}
function updUserPwd()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
if (GetCgiParam(objStr, "Username=") == 1)
top.dt.user.username = objStr.strGet;
if (GetCgiParam(objStr, "Password=") == 1)
top.dt.user.password = objStr.strGet;
loadLogin();
}
}
function loadLogin()
{
httpObj2 = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/guest/Login.cgi?rnd="+Math.random();
httpObj2.onreadystatechange = updLogin;
httpObj2.open("get", requestData, true);
httpObj2.send(null);
}
function updLogin()
{
if (httpObj2.readyState == 4 && httpObj2.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj2.responseText;
if (GetCgiParam(objStr,"Server-Language=") == 1)
{
if(objStr.strGet.toUpperCase() == "CHINESE")
top.dt.user.language = 2;
else if(objStr.strGet.toUpperCase() == "GREEK")
top.dt.user.language = 3;
else
top.dt.user.language = 1;
}
if (GetCgiParam(objStr, "Video-System=") == 1)
top.dt.user.VideoSystem = objStr.strGet;
if (GetCgiParam(objStr, "User-Level=") == 1)
top.dt.user.ulevel = objStr.strGet;
if (GetCgiParam(objStr, "Product-ShortName=") == 1)
{
if(objStr.strGet == "V_Indep")
top.dt.user.IndepFlag = true;
}
//top.dt.user.NatSupport = true;
//top.dt.user.PosSupport = true;
if (GetCgiParam(objStr, "Capability=") == 1)
{
tmpStr = objStr.strGet.split(",");
if(tmpStr.length==4){
if(parseInt(tmpStr[3],16)&0x01)
top.dt.user.isDvrPtz = true;
if(parseInt(tmpStr[2],16)&0x01)
top.dt.user.DvrHaSupport = true; // HA
if(parseInt(tmpStr[2],16)&0x02)
top.dt.account.NotifySys = true; //3G Notify
if(parseInt(tmpStr[2],16)&0x04)
top.dt.user.NatSupport = true; //NAT
if(parseInt(tmpStr[2],16)&0x08)
top.dt.user.RfidSupport = true; //RFID
if(parseInt(tmpStr[1],16)&0x01)
top.dt.user.PosSupport = true; //POS
}
}
if (GetCgiParam(objStr, "Product-ID-Minor=") == 1)
{
top.dt.user.ProductID = objStr.strGet;
var pid = objStr.strGet;
// Video Channel (default: 4 ch)
if(pid == "787" || pid == "718" || pid == "616" || pid == "757" || pid == "677" || pid == "678" || pid == "DG1648" || pid == "798"){
top.dt.user.dvrCh = 16;
}
else if (pid == "785" || pid == "608" || pid == "716" || pid == "755" || pid == "675" || pid == "676" || pid == "DG0824" || pid == "796"){
top.dt.user.dvrCh = 8;
}
else if (pid == "783" || pid == "604" || pid == "604F" || pid == "714" || pid == "724" || pid == "DG0412" || pid == "763" || pid == "764" || pid == "760A" || pid == "761A" || pid == "041"){
top.dt.user.dvrCh = 4;
}
else{
top.dt.user.dvrCh = 4; /* default 4 ch */
}
// Audio Channel
if(pid == "DG0824" || pid == "608" || pid == "DG1648" || pid == "616" || pid == "718" || pid == "757" || pid == "755" || pid == "675" || pid == "676" || pid == "677" || pid == "678" || pid == "724" || pid == "764" || pid == "673" || pid == "674" || pid == "683" || pid == "796" || pid == "798"){
top.dt.user.soundCh = 4;
}
else if (pid == "732E" || pid == "DG0412" || pid == "714"){
top.dt.user.soundCh = 2;
}
else if (pid == "733" || pid == "944" || pid == "945" || pid == "946" || pid == "311" || pid == "321" || pid == "202" || pid == "212" || pid == "604F" || pid == "203" || pid == "671" || pid == "672" || pid == "681"){
top.dt.user.soundCh = 1;
}
else{
top.dt.user.soundCh = 0;
}
//Top-Page
if(top.dt.user.ulevel != "SUPERVISOR" || pid == "203" || pid == "763")
top.dt.user.topSrc = "/top2.htm";
else
top.dt.user.topSrc = "/top.htm";
//show Left-Page
if(pid == "311" || pid == "321"){
top.dt.user.leftSrc = "/left_ipcam.htm";
top.dt.user.confSrc = "/left_ipcam_config.htm";
top.dt.user.ProductType = "IP CAMERA";
top.dt.user.isAutomoveSupport = true;
}
else if(pid == "203"){
top.dt.user.leftSrc = "/left_ipcam_h264.htm";
top.dt.user.ProductType = "IP CAMERA";
}
else{
if(pid == "763"){
top.dt.user.leftSrc = "/left_home763.htm";
}else if(pid == "798" || pid == "796"){
top.dt.user.leftSrc = "/left_home16ch.htm";
}
else{
top.dt.user.leftSrc = "/left_home.htm";
}
top.dt.user.confSrc = "/left_config.htm";
top.dt.user.ProductType = "DVR";
}
//show Title
if(pid == "764" || pid == "671" || pid == "672" || pid == "673" || pid == "674" || pid == "681" || pid == "683" || pid == "203" || pid == "796" || pid == "798" || pid == "041"){
top.dt.user.MediaType = "H264";
document.title = "H264 "+ top.dt.user.ProductType;
}
else
document.title = "MPEG4 "+ top.dt.user.ProductType;
if(top.dt.user.ulevel == "SUPERVISOR")
if(top.dt.user.ProductType == "DVR")
loadRecImageSize();
else
chkNatFirstUse();
else
loadMainPage();
}
}
}
function loadRecImageSize()
{
httpObj = createHttpRequestObj();
var requestData = "http://"+getURL()+"/cgi-bin/user/Config.cgi?action=get&category=DVR.Record.*";
httpObj.onreadystatechange = updRecImageSize;
requestCgiParam(httpObj, requestData);
}
function updRecImageSize()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
if (GetCgiParam(objStr,"ImageSize=") == 1){
top.dt.user.DVR_Record_ImageSize = objStr.strGet;
chkNatFirstUse();
}
}
}
function chkNatFirstUse()
{
httpObj = createHttpRequestObj();
var requestData = "http://"+getURL()+"/cgi-bin/user/Config.cgi?action=get&category=Network.NAT.*";
httpObj.onreadystatechange = updNatFirstUse;
requestCgiParam(httpObj, requestData);
}
function updNatFirstUse()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
var FirstUseNatFlag = false;
if (GetCgiParam(objStr,"FirstUse=") == 1)
if(objStr.strGet == "YES")
FirstUseNatFlag = true;
if (GetCgiParam(objStr,"Hostname=") == 1)
top.dt.user.NatName = objStr.strGet;
if(FirstUseNatFlag)
showNatFirstUseWeb();
else
loadMainPage();
}
}
function showNatFirstUseWeb()
{
top.ban.location.replace("/top2.htm");
top.left.location.replace("/left_empty.htm");
top.main.location.replace("/combo/nat_firstuse.htm");
}
function loadMainPage()
{
top.dt.user.mainSrc = "/home.htm";
top.ban.location.replace(top.dt.user.topSrc);
top.left.location.replace(top.dt.user.leftSrc);
}
</script>
</html>
The page actually renders perfectly
fine when being visited directly, and
not through an iframe.
The only thing I can think of that the page has a frame busting technique.
You can read a little about it here.
I can't help you much more without the code!
Related
Hy. I'm learning about Laravel
im using append to enter data in select option
here is my append code
if($('.type').val()=="MAG") {
$('.tools').empty();
$('.tools').append('<?php echo $MAGRES ?>');
$(".tools").prop('disabled', false);
$('.level').empty();
$('.level').append('<?php echo $mlevel ?>');
$(".level").prop('disabled', false);
}
if($('.type').val()=="WAG") {
$('.tools').empty();
$('.tools').append('<?php echo $WAGRES ?>');
$(".tools").prop('disabled', false);
$('.level').empty();
$('.level').append('<?php echo $flevel ?>');
$(".level").prop('disabled', false);
}
Here is my controller
$openM =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','MAG')->first();
$openF =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','WAG')->first();
$mlevel='<option value="">-- Choose Levels --</option>';
$flevel='<option value="">-- Choose Levels --</option>';
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){$mlevel=$mlevel.'<option value="Level 1">Level {{$event->onename}} </option>';}
if($openM->TwoO == 1 || $openM->TwoA == 1 || $openM->TwoB == 1 || $openM->TwoC == 1 || $openM->TwoD == 1){$mlevel=$mlevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
if($openM->ThreeO == 1 || $openM->ThreeA == 1 || $openM->ThreeB == 1 || $openM->ThreeC == 1 || $openM->ThreeD == 1){$mlevel=$mlevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
if($openM->FourO == 1 || $openM->FourA == 1 || $openM->FourB == 1 || $openM->FourC == 1 || $openM->FourD == 1){$mlevel=$mlevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
if($openM->FiveO == 1 || $openM->FiveA == 1 || $openM->FiveB == 1 || $openM->FiveC == 1 || $openM->FiveD == 1){$mlevel=$mlevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
if($openM->FigO == 1 || $openM->Fig1 == 1 ||$openM->Fig2 == 1){$mlevel=$mlevel.'<option value="FIG">FIG</option>';}
if($openF->OneO == 1 || $openF->OneA == 1 || $openF->OneB == 1 || $openF->OneC == 1 || $openF->OneD == 1){$flevel=$flevel.'<option value="Level 1">Level {{$event->onename}}</option>';}
if($openF->TwoO == 1 || $openF->TwoA == 1 || $openF->TwoB == 1 || $openF->TwoC == 1 || $openF->TwoD == 1){$flevel=$flevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
if($openF->ThreeO == 1 || $openF->ThreeA == 1 || $openF->ThreeB == 1 || $openF->ThreeC == 1 || $openF->ThreeD == 1){$flevel=$flevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
if($openF->FourO == 1 || $openF->FourA == 1 || $openF->FourB == 1 || $openF->FourC == 1 || $openF->FourD == 1){$flevel=$flevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
if($openF->FiveO == 1 || $openF->FiveA == 1 || $openF->FiveB == 1 || $openF->FiveC == 1 || $openF->FiveD == 1){$flevel=$flevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
if($openF->FigO == 1 || $openF->Fig1 == 1 ||$openF->Fig2 == 1){$flevel=$flevel.'<option value="FIG">FIG</option>';}
there is no problem to display the options
but its print text :
'{{$event->onename}}' not data from $event->onename
i want it shows $event->onename data from database.
can anyone help me? thank you
Because you are using Blade syntax in your controller file, that is why it is displaying {{$event->onename}} instead of its actual value.
You can do like
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
$mlevel= $mlevel."<option value=\"Level 1\">Level {$event->onename} </option>";
}
Or
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
$mlevel = $mlevel.'<option value="Level 1">Level '.$event->onename.'</option>';
}
I am attempting to have a script check sheet1 for first and last names (2 cells), use the first and last name of each person in sheet1, then in sheet2 check each person for a value in 4-5 rows greater than 0.
The issue is that certain names are in different columns and I need to check one column and have those names in that one column checked against a large (180 cells) list of names. This is the part where it times out.
I have the code fully functioning and working, but it uses some parts too heavily and ends up timing out. The getvalue function is used heavily and I am unsure of a better way to use it. I am looking for how to make it more efficient and or run better.
I may just have to input the names in the code to make it faster, but I was hoping for a more user-friendly approach so that names could change in sheet1 and format automatically in the script.
Thank you!
function getvalue(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2').getRange(CellName).getValues();
}
function getAdvisee(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1').getRange(CellName).getValues();
}
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
var columnAmount = 3;
var advisoryStudent = getvalue('a' + columnEnrichment);
var studentEnrichment = getvalue('g'+ columnEnrichment);
var hours = Utilities.formatDate(studentEnrichment, 'EST', 'mm');
var minutes = Utilities.formatDate(studentEnrichment, 'EST', 'ss');
var teacherEmail = getAdvisee('b2');
var student1 = getAdvisee('b3');
var student1F = getAdvisee('b3');
var student2 = getAdvisee('b4');
var student2F = getAdvisee('b4');
var student3 = getAdvisee('b5');
var student3F = getAdvisee('b5');
var student4 = getAdvisee('b6');
var student4F = getAdvisee('b6');
var student5 = getAdvisee('b7');
var student5F = getAdvisee('b7');
var student6 = getAdvisee('b8');
var student6F = getAdvisee('b8');
var student7 = getAdvisee('b9');
var student7F = getAdvisee('c9');
var student8 = getAdvisee('b10');
var student8F = getAdvisee('c10');
var student9 = getAdvisee('b11');
var student9F = getAdvisee('c11');
var student10 = getAdvisee('b12');
var student10F = getAdvisee('c12');
var student11 = getAdvisee('b13');
var student11F = getAdvisee('c13');
for (columns; columns <= LastRow && columns <= 160; columns++) {
var advisoryStudent = getvalue('a' + columns);
var advisoryStudentSp = getvalue('b' + columns);
var reminderCount = getvalue('e' + columns);
var reminderLink = getvalue('m'+columns);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if ( getvalue('e' + columns) > 0 ) {
reminders = reminders + getvalue('b' + columns) + ' ' + getvalue('a' + columns) + ': ' + reminderCount + '<br>Reminder Link: ' + reminderLink + '<br>';
}
}
}
for (columnassignments; columnassignments <= LastRow && columnassignments <= 160; columnassignments++) {
var advisoryStudent = getvalue('a' + columnassignments);
var advisoryStudentSp = getvalue('b'+columnassignments);
var assignmentCount = getvalue ('f' + columnassignments);
var assignmentLink = getvalue('n' + columnassignments);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('f' + columnassignments) > 0) {
assignments = assignments + getvalue('b' + columnassignments) + ' ' + getvalue('a' + columnassignments) + ': ' + assignmentCount + '<br>Assignment Link: ' + assignmentLink + '<br>';
}
}
}
for (columnAmount; columnAmount <= LastRow && columnAmount <= 160; columnAmount++) {
var advisoryStudent = getvalue('a' + columnAmount);
var advisoryStudentSp = getvalue('b' + columnAmount);
var amountowed = getvalue ('i' + columnAmount);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('i' + columnAmount) > 0) {
amount = amount + getvalue('b' + columnAmount) + ' ' + getvalue('a' + columnAmount) + ': ' + '$' + amountowed + '<br>';
}
}
}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Status Calculator');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
for (columnEnrichment; columnEnrichment <= LastRow && columnEnrichment <= 160; columnEnrichment++) {
var advisoryStudent = getvalue('a'+columnEnrichment);
var advisoryStudentSp = getvalue('b' + columnEnrichment);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') > 0 || Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') > 0){
enrichment = enrichment + getvalue('b' + columnEnrichment) + ' ' + getvalue('a' + columnEnrichment) + ': ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') + ' hours ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') + ' minutes <br>'
}
}
}
}
EDIT:
This portion just has a list of names in one column and searches for one word in the entire 200 row column and returns the rows with that word, then returns it again if it is greater than 5.
If I had it just looking for numbers greater than or equal to 5 and using a getvalue function, would that be the most efficient way to return names with values of 5 or more?
function getValues(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).getValues();
}
function setvalue(CellName, value) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).setValue(value);
}
function test(i) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh2 = ss.getSheetByName('Sheet2');
var data = sh2.getRange('A1:C200').getValues();
var amount = sh2.getRange('c1:c200').getValues()
var findthis = sh2.getRange('e1').getValues();
var acol = sh2.getRange(1,sh2.getLastRow(),1,1).getValues();
var bcol = sh2.getRange(1,sh2.getLastRow(), 2, 1).getValues();
var test = acol.join().split(',');
var test2 = bcol.join().split(',');
for (i = 0; i<data.length; i++) { //search all rows
if ('wet' == data[i][0]) { //finds wet in the data column and returns row
Logger.log('testing' + ' row ' + (i+1))
if (amount[i][0] >= 5) { //search if c >= 5
Logger.log('Larger ' + ' row ' + (i+1))
}
}
}
}
I would suggest grouping your data into arrays by its natural grid ranges and then accessing the values by array index.
Something along the lines of:
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh_1 = ss.getSheetByName('sheet1');
var sh_2 = ss.getSheetByName('sheet2');
...
// Get all related values into array & retrieve each row record by index
var student = sh_1.getRange("B3:C13").getValues(); // student[row][col] :ex: student11 => student[12][0]::student11F => student[12][1]
...
// remove the for loop & get all values in a col with one call per col
//(this could be optimized further)
var a_col = sh_2.getRange(1, sh_2.getLastRow(), 1, 1).getValues(); // col a rows 1-lastrow()
var b_col = sh_2.getRange(1, sh_2.getLastRow(), 2, 1).getValues(); // col b rows 1-lastrow()
// Flatten the array to make searching that column easier
var advisoryStudent = a_col.join().split(",")
var advisoryStudentSp = b_col.join().split(",")
// etc ...
// To check if student11 is in advisoryStudentSp: (can loop through students here)
// -1 means not found
// any other number is the index position of `advisoryStudentSp[i]`
// if 5 is returned then student11 matched the value in sheet2 colB row6
Logger.log("student11 is in position: %s", advisoryStudentSp.indexOf(student[12][0]))
}
edit: added the somewhat important .getValues()
Rather than retrieve the cell values one by one using your getValue() / getAdvisee() formulas you need to read the entire sheets or the relevant ranges all at once using Range.getValues(), then work with the data in the arrays.
The key issue here is that each individual call to Range.getValues() consumes a lot of time, whether you read in 100 cells at once or a single cell value. Thus your current approach of reading in one cell at a time is extremely slow (as you are seeing).
Refactoring in this way is too large to undertake as part of my answer, but once completed this script will run in just a couple seconds.
I've five fields- rate, qty. discount, cgst_percent, cgst_amount.
I want to calculate cgst_amount. The formula should be -
cgst_amount = ((rate*qty - (rate*qty*discount)/100)*cgst_percent)/100
To Start with simple steps, I tried cgst_amount = rate*qty
The javascript part is as below -
<?php
/* start getting the cgst */
$script = <<< JS
function getGst(item) {
var index = item.attr("id").replace(/[^0-9.]/g, "");
var qtyvar = ratevar = discvar = cgstpercentvar = cgstvar = 0;
var id = item.attr("id");
var myString = id.split("-").pop();
if (myString == "rate") {
fetch1 = index.concat("-qty");
fetch2 = index.concat("-discount");
fetch3 = index.concat("-cgst_rate");
} else if (myString == "qty") {
fetch1 = index.concat("-rate");
fetch2 = index.concat("-discount");
fetch3 = index.concat("-cgst_rate");
} else if (myString == "discount"){
fetch1 = index.concat("-qty");
fetch2 = index.concat("-rate");
fetch3 = index.concat("-cgst_rate");
} else {
fetch1 = index.concat("-qty");
fetch2 = index.concat("-rate");
fetch3 = index.concat("-discount");
}
temp1 = $("#productsales-"+fetch1+"").val();
temp2 = $("#productsales-"+fetch2+"").val();
temp3 = $("#productsales-"+fetch3+"").val();
//alert (temp2);
if (!isNaN(temp1) && temp1.length != 0) {
ratevar = temp1;
}
if (isNaN(temp2) || temp2.length != 0) {
discvar = temp2;
}
if (isNaN(temp3) || temp3.length != 0) {
cgstpercentvar = temp3;
}
qtyvar = item.val();
if (isNaN(qtyvar) || qtyvar.length == 0) {
qtyvar = 0;
}
//alert (qtyvar);
if (!isNaN(qtyvar) && !isNaN(ratevar) && !isNaN(discvar) && !isNaN(cgstpercentvar)) {
cgstvar = (parseFloat(qtyvar) * parseFloat(ratevar)).toFixed(2);
}
cgstField = "productsales-".concat(index).concat("-cgst_amount");
$("#"+cgstField+"").val(cgstvar);
}
JS;
$this->registerJs($script, View::POS_END);
/* end getting the cgst */
?>
Whn I key in rate and qty I get multiply of them as output in cgst_amount textbox. No problem so far. As soon as I key in anything in discount,the same texts are getting written in cgst_amount as output.
I'm not quite sure about the javascript part.
It is an extension of - Calculate from 3 inputfield in dynamic form yii2 and Calculate 3 fields and display the result in the 4th in yii2 dynamic form
If I work on the full formula, the javascript calculation part becomes - cgstvar = ((((parseFloat(ratevar) * parseFloat(qtyvar)) - (parseFloat(ratevar) * parseFloat(qtyvar) * parseFloat(discvar))/100) * parseFloat(cgstpercentvar))/100).toFixed(2);
And the example is as below image -
The actual result should have been - 5.43. Instead I'm getting -0.00
You meshed up with fields and variables, i have updated a script a bit :
function getGst(item) {
var index = item.attr("id").replace(/[^0-9.]/g, "");
var qtyvar = ratevar = discvar = cgstpercentvar = cgstvar = 0;
var id = item.attr("id");
var myString = id.split("-").pop();
quantity = index.concat("-qty");
rate = index.concat("-rate");
discount = index.concat("-discount");
cgstRate = index.concat("-cgst_rate");
temp1 = $("#productsales-"+quantity+"").val();
temp2 = $("#productsales-"+rate+"").val();
temp3 = $("#productsales-"+discount+"").val();
temp4 = $("#productsales-"+cgstRate+"").val();
if (isNaN(temp1) || temp1.length != 0) {
qtyvar = temp1;
}
if (!isNaN(temp2) && temp2.length != 0) {
ratevar = temp2;
}
if (isNaN(temp3) || temp3.length != 0) {
discvar = temp3;
}
if (isNaN(temp4) || temp4.length != 0) {
cgstpercentvar = temp4;
}
if (!isNaN(qtyvar) && !isNaN(ratevar) && !isNaN(discvar) && !isNaN(cgstpercentvar)) {
cgstvar = ((((parseFloat(ratevar) * parseFloat(qtyvar)) - (parseFloat(ratevar) * parseFloat(qtyvar) * parseFloat(discvar))/100) * parseFloat(cgstpercentvar))/100).toFixed(2);
}
cgstField = "productsales-".concat(index).concat("-cgst_amount");
$("#"+cgstField+"").val(cgstvar);
}
I just want to cancel the keydown event when I type the key except a number,
for this, I did the following :
function handleNum(obj){
var e = window.event;
var flag = true;
if( ( e.keyCode >= 48 && e.keyCode <= 57 ) ||
( e.keyCode >= 96 && e.keyCode <= 105 ) ||
e.keyCode == 8 ||
e.keyCode == 46 ||
//e.keyCode == 110 ||
//e.keyCode == 190 ||
e.keyCode == 37 ||
e.keyCode == 39 ||
e.keyCode == 35 ||
e.keyCode == 36 ||
e.keyCode == 9
) {
flag = true;
} else {
alert('You can type only a number!');
console.log("doesn't return?");
e.preventDefault();
flag = false;
}
console.log(flag);
return flag;
}
html :
<input type="text" onkeydown="return handleNum(this);" />
but It doesn't work, how can I solve this problems?
I have no idea why e.preventDefault() don't work in any browser.
Event is undefined, You can pass it like this
<script>
function handleNum(e,obj){
if (!e) var e = window.event;
var flag = true;
if( ( e.keyCode >= 48 && e.keyCode <= 57 ) ||
( e.keyCode >= 96 && e.keyCode <= 105 ) ||
e.keyCode == 8 ||
e.keyCode == 46 ||
//e.keyCode == 110 ||
//e.keyCode == 190 ||
e.keyCode == 37 ||
e.keyCode == 39 ||
e.keyCode == 35 ||
e.keyCode == 36 ||
e.keyCode == 9
) {
flag = true;
} else {
alert('You can type only a number!');
console.log("doesn't return?");
e.preventDefault();
flag = false;
obj.value = obj.value.replace(/\D/g, '');
}
console.log(flag);
return flag;
}
</script>
<input type="text" onKeyDown="return handleNum(event,this);" />
Fiddle
Here is a code that will return false if the key pressed is not a number.
Use the keypress event instead of keydown.
$(fieldid).keypress(function(e) {
if (e.which != 8 && e.which != 0 && (e.which<48 || e.which>57)) {
return false;
}
});
I have a part of code from php like this. Any two table tbl_gejala for change a sentence and tbl_hormon for move a Layout. Tbl_gejala with $id_g and tbl_hormon $id_h. and this php called by gejala.php.
I use 2 choice for this application, yes or no. $jawab == 1 for yes and $jawab == o for no.
$id_g = $_GET['id_g'];
$jawab = $_GET['a'];
$link = mysql_connect('localhost', 'root', '') or die ('Tidak bisa menampilkan');
mysql_select_db('hormon', $link) or die('Tidak bisa select');
if($id_g == 1 && $jawab == 1){
$query = "SELECT * from tbl_gejala where id_g = 3";
}elseif($id_g == 3 && $jawab == 1){
$query = "SELECT * from tbl_gejala where id_g = 5";
}elseif($id_g == 5 && $jawab == 1){
//intent activity and parseJSON with table hormon
$query = "SELECT * from tbl_hormon where id_h = 16";
}elseif($id_g == 5 && $jawab == 0){
$query = "SELECT * from tbl_gejala where id_g = 10";
}elseif($id_g == 10 && $jawab == 1){
$query = "SELECT * from tbl_hormon where id_h = 1";
}elseif($id_g == 10 && $jawab == 0){
$query = "SELECT * from tbl_hormon where id_h = 7";
I want to parseJSON with gejala.php in konsultasi.class
I have try this coding, but any problem by logic error. This coding like this:
void parseJSON(String response) {
try {
JSONObject json = new JSONObject(response);
listArray = new ArrayList<ListModel>();
JSONArray jArray = json.getJSONArray("Hormon");
log("lenght: " + jArray.length());
for (int i = 0; i < jArray.length(); i++) {
JSONObject jData = jArray.getJSONObject(i);
if(idPert.equals("5")&&yes.equals("1") ||
idPert.equals("7")&&yes.equals("1") ||
idPert.equals("11")&&yes.equals("1") ||
idPert.equals("11")&&no.equals("0") ||
idPert.equals("10")&&yes.equals("1") ||
idPert.equals("16")&&yes.equals("1") ||
idPert.equals("19")&&yes.equals("1") ||
idPert.equals("20")&&yes.equals("1") ||
idPert.equals("20")&&no.equals("0") ||
idPert.equals("8")&&yes.equals("1") ||
idPert.equals("17")&&yes.equals("1") ||
idPert.equals("17")&&no.equals("0") ||
idPert.equals("6")&&yes.equals("1") ||
idPert.equals("13")&&yes.equals("1") ||
idPert.equals("13")&&no.equals("0") ||
idPert.equals("12")&&yes.equals("1") ||
idPert.equals("14")&&yes.equals("1") ||
idPert.equals("15")&&yes.equals("1") ||
idPert.equals("18")&&yes.equals("1") ||
idPert.equals("21")&&yes.equals("1") ||
idPert.equals("22")&&yes.equals("1") ||
idPert.equals("10")&&no.equals("0")) {
id_h = jData.getString("id_h");
nm_penyakit = jData.getString("nm_penyakit");
definisi = jData.getString("definisi");
gejala = jData.getString("gejala");
penyebab = jData.getString("penyebab");
solusi = jData.getString("solusi");
gambar = jData.getString("gambar");
munculPenyakit = true;
}else{
idPert = jData.getString("id_g");
pertanyaan = jData.getString("gejala2")+"?";
munculPenyakit = false;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Please help me, thanks a lot before.