It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Managing variables

Managing variables

Postby rebelrebellious on Mon Nov 24, 2008 4:49 pm

Code: Select all
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,
rebelrebellious
 
Posts: 4
Joined: Mon Nov 24, 2008 4:43 pm

Postby rebelrebellious on Mon Nov 24, 2008 6:21 pm

Code: Select all
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.
rebelrebellious
 
Posts: 4
Joined: Mon Nov 24, 2008 4:43 pm

Postby rebelrebellious on Mon Nov 24, 2008 7:12 pm

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: Select all
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;
}
rebelrebellious
 
Posts: 4
Joined: Mon Nov 24, 2008 4:43 pm

Postby rebelrebellious on Mon Nov 24, 2008 7:21 pm

And this is how I am setting up variables

Code: Select all
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
rebelrebellious
 
Posts: 4
Joined: Mon Nov 24, 2008 4:43 pm


Who is online

Users browsing this forum: No registered users and 3 guests