Source language: Translate to:

Using an object to check value changes...

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

Using an object to check value changes...

Postby David de Argentina » Wed Mar 11, 2015 10:19 am

Hi all,

My program receives data from a php file.
Data is retrieved as a table.

Each time user touch or click a row, a javascript function (within the php file) tell to the main program that row_id value was changed.
In fact, all works fine.
I can get the new row_id in the main program.

I need check on the main program that the received new row_id is not the same previous value.
If it is a different value, i need launch a function that does some actions.

I tried to store the received row_id into a InputBox object, because this object has the event "change".
New value is stored into the InputBox object, but the "change" event is never fired. Only works when phisically change the value via keyboard.

Does any know another object that fires a "change" event without phisical intervention ?

Any ideas ?

Thanks in advance,
David de Argentina
User avatar
David de Argentina
 
Posts: 1559
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: Using an object to check value changes...

Postby Gaev » Wed Mar 11, 2015 10:55 am

David de Argentina:

I am confused by the "terms" you use in describing the functionality of your App.

My program receives data from a php file.
Is the "php file" ... a "php script on a server" that is called (e.g. via AJAX) from your (client side) App ?

Data is retrieved as a table.
Do you mean something like this text string ? ...
Code: Select all
<table><tr><td>A</td><td>B</td></tr><tr><td>X</td><td>Y</td></tr></table>


Each time user touch or click a row, a javascript function (within the php file) tell to the main program that row_id value was changed.

I can get the new row_id in the main program.
What is a "Javascript function (within the php file)" ? ... what is "main program" ? ... howw is this communicated ?


Normal practice in Apps is to have the "touch event handler/function" invoke an AJAX call to the server side ... with a "defined function" to be serviced upon receipt of the response ... the Browsers take care of all the bookkeeping associated with such Async. processing ... one way of keeping track of changes would be for the client side to pass the "row-id" as a parameter to the server side ... and have the server side return this value in its response ... so the function that handles such responses has both the "sent row_id" and the new data.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Using an object to check value changes...

Postby David de Argentina » Wed Mar 11, 2015 11:18 am

Thanks gaev,

Is the "php file" ... a "php script on a server" that is called (e.g. via AJAX) from your (client side) App ?
Yes


I receive this url within a Container object:

http://www.neoespecialistas.com.ar/html5/index.php

The index.php file is

Syntax: [ Download ] [ Hide ]
Using PHP Syntax Highlighting
<?php
header("Access-Control-Allow-Origin: *");

$link = mysql_connect('mysql.server', 'userid', 'userpass') or die('Could not connect: ' . mysql_error());
mysql_select_db('mydatabase') or die('Could not select database');
mysql_set_charset('utf8');

$query = "Select * from mytable";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

echo '<!DOCTYPE html>';
echo '<html>';
echo '<head>';
echo '<style>';
echo 'table {width:100%;}';
echo 'table, th, td {border: 1px solid black;border-collapse: collapse;}';
echo 'th, td {padding: 15px 15px; text-align: left;}';
echo 'table tr:nth-child(even) {background-color: #eee;}';
echo 'table tr:nth-child(odd) {background-color:#fff;}';
echo '</style>';

echo '<script type="text/javascript">';
echo 'function ver(cual) { ';
echo '  var a = "A" + cual;';
echo '  var b = "BB" + cual;';
echo '  var c = "C" + cual;';
echo '  var d = "D" + cual;';
echo '  var e = "E" + cual;';
echo '  var f = "F" + cual;';

echo '  selected_cual = document.getElementById(a).innerHTML;';
echo '  selected_quien = document.getElementById(b).innerHTML;';
echo '  selected_casa = document.getElementById(c).innerHTML;';
echo '  selected_celular = document.getElementById(d).innerHTML;';
echo '  selected_nextel = document.getElementById(e).innerHTML;';
echo '  selected_trabajo = document.getElementById(f).innerHTML;';
echo '  alert(selected_quien + " - " + selected_trabajo)';

echo '}';
echo '</script>';

echo '</head>';
echo '<body>';
echo '<table border="1" style="width:100%">';

while ($fila = mysql_fetch_array($result, MYSQL_BOTH)) {
  echo '<tr>';
  echo '<td id=A' . $fila["id"] . ' style="display:none;">'  . $fila["id"] . "</td>";
  echo '<td id=B' . $fila["id"] . ' style="width:100%;"> <a id=BB' . $fila["id"] . ' href="javascript&#058;selected_cual='  . $fila["id"] . ';";>'  . $fila["nombre"] . "</a></td>";
  echo '<td id=C' . $fila["id"] . ' style="display:none;">'  . $fila["particular"] . "</td>";
  echo '<td id=D' . $fila["id"] . ' style="display:none;">'  . $fila["celular"] . "</td>";
  echo '<td id=E' . $fila["id"] . ' style="display:none;">'  . $fila["nextel"] . "</td>";
  echo '<td id=F' . $fila["id"] . ' style="display:none;">'  . $fila["trabajo"] . "</td>";
}

echo '</tr>';
echo '</table>';

echo '</body>';
echo '</html>';
mysql_free_result($result);
mysql_close($link);
?>
Parsed in 0.100 seconds, using GeSHi 1.0.8.10


As you can see, i have a Javascript function called "ver(cual)".
If i change this line: ( this line works fine.)

Code: Select all
echo '<td id=B' . $fila["id"] . ' style="width:100%;"> <a id=BB' . $fila["id"] . ' href="javascript:selected_cual='  . $fila["id"] . ';";>'  . $fila["nombre"] . "</a></td>";


for something like:

Code: Select all
echo '<td id=B' . $fila["id"] . ' style="width:100%;"> <a id=BB' . $fila["id"] . ' href="javascript:ver('  . $fila["id"] . ');";>'  . $fila["nombre"] . "</a></td>";


I receive an error message like "Javascript function not found"

Is for this reason i'm trying to check the change value of "selected_cual" variable into the main program, and fires some control process.

Thanks again,
David de Argentina
User avatar
David de Argentina
 
Posts: 1559
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: Using an object to check value changes...

Postby Gaev » Wed Mar 11, 2015 12:57 pm

David de Argentina:

I receive an error message like "Javascript function not found"
When you receive the "echo" text in your App, do you just place "all of it" in a "container" ? ... including the <html></html> and <head></head> tags ?

1) Try and have the commands for the function called ver in your App ... i.e. in the resulting window from Project >>> App Events ..., enter ...

a) either ...

Code: Select all
BeginJS
   $.getScript("http://www.neoespecialistas.com.ar/html5/ver.js");
EndJS


b) or ...

Code: Select all
BeginJS

function ver(cual) {

var a = "A" + cual;
var b = "BB" + cual;
var c = "C" + cual;
var d = "D" + cual;
var e = "E" + cual;
var f = "F" + cual;

selected_cual = document.getElementById(a).innerHTML;
selected_quien = document.getElementById(b).innerHTML;
selected_casa = document.getElementById(c).innerHTML;
selected_celular = document.getElementById(d).innerHTML;
selected_nextel = document.getElementById(e).innerHTML;
selected_trabajo = document.getElementById(f).innerHTML;
alert(selected_quien + " - " + selected_trabajo);

}

EndJS

Hopefully, that should make it "globally available" to any event in any object.


2) You might look into some "best practices for client-server communications" ... i.e. only pass data (not layout and code) ... in your example, you should pass just the values for the various <td> elements ... e.g. in an array of objects/arrays ... on receipt of this data, the required html can be generated via a javascript function (built into your App).
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron