Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sat Nov 21, 2009 10:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ]  Bookmark and Share
Author Message
 Post subject: Managing variables
PostPosted: Mon Nov 24, 2008 5:49 pm 
Offline

Joined: Mon Nov 24, 2008 5:43 pm
Posts: 4
Code:
function set_var(name, value){
    if(this.form.getElementById('name') != null){
        this.form.getElementById('name').value = value;
    } else {
        this.create(name, value);
    }
}

function present_vars(){
    var returnstring = '';
    var count = this.form.length;
    for(index=0; index<count; index++){
        returnstring = returnstring + '&' + name + '=' +
this.form.elements[index].value;
    }
    return returnstring;
}

function present_vars(name){
    return '&' + name + '=' + this.form.getElementById('name').value;
}

function create_var(name, value){
    var input = document.createElement('input');
    input.setAttribute('type', 'text');
    input.setAttribute('value', value);
    input.setAttribute('name', name);
    input.setAttribute('id', name);
    //input.setAttribute('disabled', 'disabled');
    this.form.appendChild(input);
}

function variables_handler(form_id){
    this.form = document.getElementById(form_id);
    this.set = set_var;
    this.present = present_vars;
    this.create = create_var;
}

function query(){
    var variables = new variables_handler('variables');
    var queryString = variables.present();
    var queryaction = variables.present('queryaction');
    ajaxFunction('_self', 'query', queryString, query_ORSC, 'text');
}



ajaxFunction works.
My expectation is that when I call query, query will instantiate the variables_handler object then use it,
but the present function is returning undefined.

Thank you,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 7:21 pm 
Offline

Joined: Mon Nov 24, 2008 5:43 pm
Posts: 4
Code:
function set_var(name, value){
   if(this.form.getElementById('name') != null){
      this.form.getElementById('name').value = value;
   } else {
      this.create(name, value);
   }
}

function present_vars(name){
   if (name == null) {
      return '&' + name + '=' + this.form.getElementById(name).value;
   }
   var returnstring = '';
   var count = this.form.length;
   for(index=0; index<count; index++){
      returnstring = returnstring + '&' + name + '=' + this.form.elements[index].value;
   }
   return returnstring;
}

function create_var(name, value){
   var input = document.createElement('input');
   input.setAttribute('type', 'text');
   input.setAttribute('value', value);
   input.setAttribute('name', name);
   input.setAttribute('id', name);
   //input.setAttribute('disabled', 'disabled');
   this.form.appendChild(input);
}

function variables_handler(form_id){
   this.form = document.getElementById(form_id);
   this.set = set_var;
   this.present = present_vars;
   this.create = create_var;
}


I have corrected the function overloading and I noticed that the quotes around name in that petElementById(name) were incorrect.

There is still something wrong. When I call variables.add('var_one', 'value'); firefox tells me that this.form is null.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 8:12 pm 
Offline

Joined: Mon Nov 24, 2008 5:43 pm
Posts: 4
Thinking that the old this.form variable was pointing to outdated element, I have changed the code so that the form variable is set at the time of the function call. Now, when I call variables.set I get the error, variables.set is not a function. Does anyone know what I am doing wrong here? Thank you for taking a look.

Code:
function set_var(name, value){
   var form = document.getElementById(this.form_id);
   if(form.getElementById(name) != null){
      form.getElementById(name).value = value;
   } else {
      this.create(name, value);
   }
}

function present_vars(name){
   var form = document.getElementById(this.form_id);
   if (name == null) {
      return '&' + name + '=' + form.getElementById(name).value;
   }
   var returnstring = '';
   var count = form.length;
   for(index=0; index<count; index++){
      returnstring = returnstring + '&' + name + '=' + form.elements[index].value;
   }
   return returnstring;
}

function create_var(name, value){
   alert('creating a variable');
   var form = document.getElementById(this.form_id);
   var input = document.createElement('input');
   input.setAttribute('type', 'text');
   input.setAttribute('value', value);
   input.setAttribute('name', name);
   input.setAttribute('id', name);
   //input.setAttribute('disabled', 'disabled');
   form.appendChild(input);
}

function variables_handler(form_id){
   this.form_id = form_id;
   this.set = set_var;
   this.present = present_vars;
   this.create = create_var;
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 8:21 pm 
Offline

Joined: Mon Nov 24, 2008 5:43 pm
Posts: 4
And this is how I am setting up variables

Code:
var variables;
function onloadFunction(){
   query('', 'id', 'DESC', '0', '', '');
   variables = new variables_handler('variables');
   variable.status = 'exists';
}

window.onload = onloadFunction;



When I call alert(variables.status); the response is undefined


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley