SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2005
    Posts
    527
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Some parameters in a function

    Hi
    I want updatate a part of my page by a function I used prototype

    I have to use a function for each ajax data loading.

    my functions are like these :

    Code:
    function function1()
    {
    	var url = 'display.php?page=messageboard&do=add&admin=1';
    	var name = $F('name');
    	var text = $F('text');
    	var dir = $F('dir');
    	var fixed = $F('fixed');
    	var pars = 'fill=1&name='+name+'&text='+text+'&dir='+dir+'&fixed='+fixed;
    	loading();	
    	var myAjax = new Ajax.Updater(
    		'div_module',
    		url,
    		{
    			method: 'post',
    			parameters: pars,
    			onFailure: reportError,
    			evalScripts:true
    		}
    	);
    }
    
    
    function function2()
    {
    			var url = 'display.php?page=users&do=signin';
    			var user = $F('user');
    			var pass = $F('pass');
    			var pars = 'fill=1&user='+user+'&pass='+pass;
    			loading();			var myAjax = new Ajax.Updater(
    			'div_module',
    			url,
    			{
    				method: 'post',
    				parameters: pars,
    				onFailure: reportError,
    				evalScripts:true
    			}
    			);
    }

    This function give the value of forms and submit to a PHP page and load the result in a Div tag
    This functions are similar.
    So I want use only a function that do works of all these functions , all the parameters be in an array like these :

    Code:
    function allFunctions(allParametersArray)
    {
    	var url = 'display.php?and add all parameters whit their value like above samples
    	.
    	.
    	.
    	loading();
    	var myAjax = new Ajax.Updater(
    			'div_module',
    			url,
    			{
    				method: 'post',
    				parameters: pars,
    				onFailure: reportError,
    				evalScripts:true
    			}
    			);
    }

    Can you help me how complete this function ?
    How get values in array and split it in function

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    If you don't want to pass anything and interpret the $F function as it is, you can use the following

    Code Javascript:
    function allFunctions() {
        var url = 'display.php';
        var arg = [];
        for (var name in $F) {
            arg.push(name + '=' + $F(name));
        }
        if (arg.length > 0) {
            url += '?' + arg.join('&');
        }
        ...
    }

    Or, if you want to pass specific values instead, the following lets you pass the arguments as follows:
    allFunctions({user: $F('user'), pass: $F('pass')});

    Code Javascript:
    function allFunctions(args) {
        var url = 'display.php';
        var arg = [];
        for (var name in args) {
            arg.push(name + '=' + args(name));
        }
        if (arg.length > 0) {
            url += '?' + arg.join('&');
        }
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •