jquerymobile selectmenu fails - sqlite

i'm trying to create a categories list with Jquerymobile-html5 and websql/sqlite.
i post my code here to hope someone sees what i do wrong.
//load the cats to choose a cat
function loadCatOptions() {
var option_str='';
option_str += '<option value="0" data-placeholder="true">Choose categorie</option>';
//option_str += '<option value="0">Top/ParentiD</option>';
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM categories', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
var r = results.rows.item(i);
var catID = r.categories_id;
}
var count =0;
while (count < catID+1){
count;
tx.executeSql('SELECT c.parent_id, c.categories_id, cd.categories_name, c.categories_image FROM categories c, categories_description cd WHERE c.categories_id ='+ count +' AND cd.categories_id ='+ count +' and cd.language_id ="1" ORDER BY sort_order, cd.categories_name', [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
var r2 = results.rows.item(i);
option_str += "<option value=" + r2['categories_id'] + ">" + r2['categories_name'] + "</option>";
console.log('categoriesname='+ r2['categories_name']);
$("#parent_id").html(option_str).selectmenu('refresh', true);
}
});
count++;
}
});
});
}
The consolelog shows all items by its name, so i'm sure that the database query is correct.
I might have spend days to someting what wasnt the problem at all.
if i take only the SELECT * query and call the selectmenu, i can see all categorie_id's in the list (ofcourse replace categories_name by categories_id to got that to work).
So the problem now is with jquerymobile??????????????
It wont read the option_str += inside the second database query!
aaargg
Code above is updated with the fix.

From your question:
Problem fixed
old code:
option_str += "<option value=" + r2['categories_id'] + ">" + r2['categories_name'] + "</option>";
console.log('categoriesname='+ r2['categories_name']);
}
});
count++;
}
$("#parent_id").html(option_str).selectmenu('refresh', true);//Moved below closing tag of count++
});
});
}

Related

How do scrape table from the provided website using casperjs?

The final goal is to retrieve stock data in table form from provided broker website and save it to some text file. Here is the code, that I managed to compile so far by reading few tutorials:
var casper = require("casper").create();
var url = 'https://iqoption.com/en/historical-financial-quotes?active_id=1&tz_offset=60&date=2016-12-19-21-59';
var terminate = function() {
this.echo("Exiting ...").exit();
};
var processPage = function() {
var rows = document.querySelectorAll('#mCSB_3_container > table'); //get table from broker site (copy/paste via copy selector in chrome tools)
//var nodes = document.getElementsByClassName('mCSB_container');
this.echo(rows);
this.echo(rows.length);
for (var i = 0; i < rows.length; i++)
{
var cell = rows[i].querySelector('.quotes-table-result__date');
this.echo(cell); //print each cell
}
};
casper.start(url);
casper.waitForSelector('#mCSB_3_container', processPage, terminate);
casper.run();
This code should retrieve the stock price table and print out each cell. However, all what I get is 'undefined', which likely means that I got no objects returned by queryselector call. And please assume that I don't know any web programming (HTML,CSS).
First of all, on problem is that the waitFor wasn't set so good, you have to wait for the rows/cells.
The Nodes you get out on this page are a bit wired,if anybody got a more abstract solution where ChildNodes are better handled that in my solution i would be really interested:
var casper = require('casper').create();
var url = 'https://eu.iqoption.com/en/historical-financial-quotes?active_id=1&tz_offset=60&date=2016-12-19-21-59';
var length;
casper.start(url);
casper.then(function() {
this.waitForSelector('#mCSB_3_container table tbody tr');
});
function getCellContent(row, cell) {
cellText = casper.evaluate(function(row, cell) {
return document.querySelectorAll('table tbody tr')[row].childNodes[cell].innerText.trim();
}, row, cell);
return cellText;
}
casper.then(function() {
var rows = casper.evaluate(function() {
return document.querySelectorAll('table tbody tr');
});
length = rows.length;
this.echo("table length: " + length);
});
// This part can be done nicer, but it's the way it should work ...
casper.then(function() {
for (var i = 0; i < length; i++) {
this.echo("Date: " + getCellContent(i, 0));
this.echo("Bid: " + getCellContent(i, 1));
this.echo("Ask: " + getCellContent(i, 2));
this.echo("Quotes: " + getCellContent(i, 3));
}
});
casper.run();

Write custom plugins/extensions like kendoui and telerik for asp.net mvc razor

Telerik and kendoUI offers a number of html controls like grids, charts etc. to enhance the ui in asp.net mvc. More interesting thing is they are used as html extensions and hence we can bind some model to the controls which also makes it somewhat strongly typed. It also uses javascript libs to handle client side interactions. I need to get some gist over how can we write custom plugins like kendo and telerik like building my own grid component. What is the proper pattern that i should follow?
This is not good example but i think it is good start.
This method generates dataTable
public static string GenerateTableHtml<TValue>(IEnumerable<TValue> model, string DeleteUrl, string EditUrl)
{
StringBuilder Table = new StringBuilder();
Table.AppendLine("<script type='text/javascript'> $(document).ready(function () {"
+ "$('.btnDelete').click(function () {"
+ "var url = $(this).attr('dropzone');"
+ "$('#dialog-form').attr('action', url);})"
+ "})</script>");
Table.AppendLine(" <div class=\"dataTables_wrapper\"><div class=\"\">");
string TableButtonsTemplate = "<td><div class=\"table_buttons\">"
+ "<img src=\"../Images/icons/dark/pencil.png\")\" title=\"რედაქტირება\" />"
+ "<a href=\"#\" id=\"opener\" class=\"btnDelete\" dropzone=\"{1}\">"
+"<img class=\"\" src=\"../Images/icons/dark/close.png\")\" title=\"წაშლა\" /></a>"
+ "</div></td>";
string TableButtons = String.Empty;
bool HaveActionButtons = false;
string rowID = string.Empty;
if (String.IsNullOrEmpty(DeleteUrl) == false || string.IsNullOrEmpty(EditUrl) == false)
{
HaveActionButtons = true;
}
Table.AppendLine("<table class=\"display dTable\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">");
Table.AppendLine("<thead>");
Table.AppendLine("<tr>");
int ColumnIndex = 0;
int rowIndexer = 0;
var fType = model.GetType().FullName;
var startIndex = fType.IndexOf("[[") + 2;
var type = fType.Substring(startIndex, fType.Length - startIndex - 2);
foreach (var item in model)
{
if (ColumnIndex == 0)
{
var properties = item.GetType().GetProperties();
foreach (var prop in properties)
{
var metaData = ModelMetadataProviders.Current.GetMetadataForProperty(null,
Type.GetType(type), prop.Name);
if (metaData.DisplayName != null)
{
Table.AppendLine("<th class=\"ui-state-default\" rowspan=\"1\" colspan=\"1\">" + metaData.DisplayName + "</th>");
}
else
{
Table.AppendLine("<th class=\"ui-state-default\" rowspan=\"1\" colspan=\"1\">" + prop.Name + "</th>");
}
}
Table.AppendLine("<th></th>");
Table.AppendLine("</tr>");
Table.AppendLine("</thead>");
Table.AppendLine("<tbody>");
}
foreach (var value in item.GetType().GetProperties().Select(x => x.GetValue(item, null)))
{
int rowCount = item.GetType().GetProperties().Select(x => x.GetValue(item, null)).Count();
rowIndexer++;
if (rowIndexer != rowCount)
{
if (rowIndexer == 1)
{
Table.AppendLine("<tr class=\"gradeA odd\">");
}
if (value != null)
{
string val = value.ToString();
Table.AppendLine("<td>" + val + "</td>");
rowID = item.GetType().GetProperty("ID").GetValue(item, null).ToString();
}
else
{
Table.AppendLine("<td></td>");
}
}
else
{
if (value != null)
{
Table.AppendLine("<td>" + value.ToString() + "</td>");
}
else
{
Table.AppendLine("<td></td>");
}
if (HaveActionButtons == true)
{
Table.AppendLine(String.Format(TableButtonsTemplate, EditUrl + rowID, DeleteUrl + rowID));
}
Table.AppendLine("</tr>");
if (rowIndexer != item.GetType().GetProperties().Count())
{
Table.AppendLine("<tr class=\"gradeA odd\">");
}
}
}
rowIndexer = 0;
ColumnIndex++;
}
Table.AppendLine("</tbody></table></div></div>");
Table.AppendLine(String.Format(Resources.MainResources.ModalDialogConfirm, "Confirmation",
"<strong>Warning!</strong><br /> Are you sure you want to delete user?", ""));
return Table.ToString();
}

Javascript: cookie doesn't expire

I'm trying to expire a cookie right after it has set, due to cookielaw restrictions in UK and NL.
Here is the code I now use:
(function ($) {
$(document).ready(function(){
if (!CookieControl.maySendCookies()) {
var now = new Date();
var expirationDate = new Date();
expirationDate.setDate(now.getDate() - 7);
alert(getCookieValue('has_js'));
document.cookie='has_js=1;expires=' + expirationDate.toGMTString();
alert(getCookieValue('has_js'));
}
});
})(jQuery);
The getCookieValue function is a function from another document to check it the cookie is actually gone. Before I expire the cookie, the value is 1, as it should be. However, when I have expired the cookie by using document.cookie='has_js=1;expires=' + expirationDate.toGMTString(); I check the value again, and it is still there.
I seriously cannot figure out why it is not being removed. I cannot wait for sessions or whatever to expire, that is not according to NL law.
Anyone any suggestions?
CMS: Drupal / Domain: localhost
it may be related to path, i don't know, but you can use below scripts:
function getCookieValue(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
return unescape(c.substring(nameEQ.length, c.length));
}
return null;
}
function setCookieValue(name, value, days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + escape(value) + expires + "; path=/";
}
function delCookieValue(name) {
Set_Cookie(name, '', -1);
}
$(document).ready(function(){
if (!CookieControl.maySendCookies()) {
delCookieValue("has_js");
}
});

extjs 4.0 retrieve grid values

The code below is for getting a Json string for the selected rows in a grid.
However this feels rather clumsy or is the way to go for extjs 4?
var json = "[";
var selrows = g.getView().getSelectionModel().getSelection();
for (var r=0; r<selrows.length; r++) {
var selrow = selrows[r];
json += "{";
for (var f=0; f<selrow.fields.length; f++) {
var n = selrow.fields.items[f].name;
var v = selrow.data[n];
json += "'" + n + "' : '" + v + "',";
}
json += "},";
}
json += "]";
alert(json);
In Firebug I see a json-alike representation of the selrow var but I can't seem to get hold of it in javascript.
Try this:
json = Ext.JSON.encode(g.getView().getSelectionModel().getSelection().map(function(e){ return e.data; }));
alert(json);

get value of dynamiclly created radiobuttonlist

I'm trying to get the value of a dynamically created radiobuttonlist via javascript to call a pagemethod.
This is how I'm creating the rbl:
rbl.Attributes["onclick"] = "javascript:preview('" + rbl.ID + "','" + rbl.ClientID + "');";
And this is the javascript:
function preview(controlid, clientid)
{
var radio = document.getElementsByName(clientid);
var answer = "k";
for (var ii = 0; ii < radio.length; ii++)
{
if (radio[ii].checked)
answer = radio[ii].value;
}
PageMethods.SaveAnswer(controlid, answer);
}
The problem however is that I want to get the groupname of the radiobuttionlist so I can use getElementsByName, but i have no luck so far.
Kind regards,
Mark
Ah well I got a temporary solution for now just to continue..
<script type="text/javascript" language="javascript">
function SaveAnswer(ctrlid)
{
var answer;
var radio = document.getElementsByName('ctl00$cphContent$' + ctrlid);
for (var ii = 0; ii < radio.length; ii++)
{
if (radio[ii].checked)
answer = radio[ii].value;
}
PageMethods.SaveAnswer(ctrlid, answer);
}
function onComplete(res)
{
//alert(res);
}
</script>
As you can see, I added ctrl00$cphContent$ by hand.

Resources