Delphi For PHP Forums    

Go Back   Delphi-PHP Forums > Programming > Javascript and Ajax
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

Javascript and Ajax Questions and information about working with Ajax and Javascript in Delphi for PHP.

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13th November 2008, 22:50
405hp's Avatar
Firebug Fanatic
Join Date: Dec 2007
Location: State of Confusion
Posts: 2,556
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default Favorite Functions to add to common.js

EDIT this thread is where I'm trying to get this included into the vcl. If you like the idea please jump in and help out.
================================================== ==============

Cut and paste this code block at the end of common.js (you will find it at vcl/js/common.js)
$:function ()
var elements = new Array();
for (var i = 0; i < arguments.length; i++)
var element = arguments[i];
if (typeof element == 'string')
element = findObj(element);
if (arguments.length == 1)
return element;

return elements;
int:function(obj){ return parseInt(vcl.$(obj).value);},
real:function(obj){ return parseFloat(vcl.$(obj).value);},
escape:function(obj){ return escape(vcl.$(obj).value);},
unescape:function(obj){ return unescape(vcl.$(obj).value);},
focus:function(obj){ vcl.$(obj).focus();},
check:function(obj){ vcl.$(obj).checked=true;},
uncheck:function(obj){ vcl.$(obj).checked=false;},
hide:function(obj){ vcl.$(obj).style.display = 'none';},
show:function(obj){ vcl.$(obj).style.display = '';},
find:function(obj){ return vcl.$(obj);},
text:function(obj){ return vcl.$(obj).value;},
value:function(obj){ return vcl.$(obj).value;},
theObj=vcl.$(incoming); = value/10; = 'alpha(opacity=' + value*10 + ')';

function createHTTPrequest()
{ /* Firefox, Opera 8.0+, Safari */
try {return new XMLHttpRequest();}
catch (error) {}
/* newer IE */
try {return new ActiveXObject("Msxml2.XMLHTTP");}
catch (error) {}
/* older IE */
try {return new ActiveXObject("Microsoft.XMLHTTP");}
catch (error) {}
throw new Error("Your browser does not have AJAX support!");
function basicAjax (url,parameters,callback)
if (callback) {xmlHttp.onreadystatechange=callback;}
if (xmlHttp.status == 200)
{alert("Sorry, received a server error ="+xmlHttp.statusText);}
if (typeof(basicAjaxAsyncFalse) != 'undefined' && basicAjaxAsyncFalse==1)"POST",url,false); //this will force a wait for return
xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59GMT");
We will add to this as more are found.


createHTTPrequest() the base function for basic ajax

function basicAjax (url,parameters,callback) a general all purpose ajax routine as explained in Basic Ajax for d4php

url = "ajax_update.php";
parameters = "code=12345&qty=2&user=me";
callback can be left blank to just run eval or if it exist it will be the function that will be called upon return.
sample files here
 //call basicAjax but override the eval function 

//call basicAjax using the built in eval function 
var params='value1='+vcl.$('Edit1').value+'&value2='+vcl.$('Edit2').value;
vcl.$() replacement for document.getElementById() and findObj()

PHP Code:
// Sample Usage:
               function Button2JSClick($sender, $params)

alert(vcl.$('Edit1').value);//just get one object

//these 3 are identical
var obj1 = document.getElementById('Edit1');
var obj2 = vcl.$('Edit1');
var obj3= FindObj('edit1');


//this gets an array of objects!! (includes obj we all ready had found also
// and real objects like LabeledEdit)
var elements = vcl.$('Edit2','Edit4','Edit6',obj1,obj2,'Edit5','Edit3');
for (var i=0;i < elements.length; i++) elements[i].value='';
//we just blew through a bunch of edits and cleared them.
// fyi this wouldn't work this way with the labeled edits though - they need setValue('')

visibility switcher - shows and hides
// Sample Usage:
And many more
//fade out 5=50%
//fwiw I did this one with a for loop to slowly fade in something
//convert an edit into a number
//put a check into a checkbox or radio button

Last edited by 405hp; 6th December 2008 at 18:29. Reason: A new revision :)
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT +1. The time now is 09:07.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use