Rebelrebellious Posted November 24, 2008 Share Posted November 24, 2008 I suspect that I may have a few problems here. My intent is for there to be a form with an id="variables" that is initially created by the php and is the source of the initial variable state. The hariable_handler object is intended to manager the changes of the variables.The present method is meant to present a querystring that can be passed back to the server through ajax GET or POST actions. The other option, when the entire page can be reloaded is to simply submit the variables form. the ajax and form submit functions are not shown here because I believe that the problem has to do with the scope and/or my use/misuse of objects and methods. I am getting an error: variables.set is not a function from the onchange event. Thank you for any help you can offer. the javascript: 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; } function query(queryaction, sortval, order, page_num, id_list, search_terms){ if(arguments.length == 0){ // this is the case for this example. The goal is to be able to quit passing all of these variables around as in the else case var variables = new variables_handler('variables'); var queryString = variables.present(); var queryaction = variables.present('queryaction'); if((queryaction == 'Delete') && (id_list != '')){ var answer = confirm("Are you SURE you want to delete Prospect with id " + id_list + "?") if (answer){ ajaxFunction('_self', 'query', queryString, query_ORSC, 'text'); } }else{ ajaxFunction('_self', 'query', queryString, query_ORSC, 'text'); } } else { var queryString = "&queryaction=" + queryaction + "&sortval=" + sortval + "&order=" + order + "&page_num=" + page_num + "&id_list=" + id_list + "&search_terms=" + search_terms; if((queryaction == 'Delete') && (id_list != '')){ var answer = confirm("Are you SURE you want to delete Prospect with id " + id_list + "?") if (answer){ ajaxFunction('_self', 'query', queryString, query_ORSC, 'text'); } }else{ ajaxFunction('_self', 'query', queryString, query_ORSC, 'text'); } } } var variables; function onloadFunction(){ query('', '<?php echo $sortval; ?>', '<?php echo $order; ?>', '<?php echo $page_num; ?>', '', '<?php echo $search_terms; ?>'); this.variables = new variables_handler('variables'); this.variables.status = 'exists'; alert(variables.status); } window.onload = onloadFunction; and the php: $priority = n; // 1, 2, or 3 for example echo '<input type="checkbox" name="priority_filter[]" value="'. $priority .'"'. (in_array($priority, $priority_search) ? ' checked="checked"' : '') .' onchange="alert(variables.status); variables.set(\'priority_filter['. $priority .']\', \''. $priority .'\'); query();" />'. $priority; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.