Saturday, February 4, 2012

Looping through XML with jQuery

Handling Xml on web pages is used to be a headache when i started coding ajax events. Most of the times we will be knowing the tag name of particular data we need and we can use

 But this is not always the case with xml.
I have a scenario in which i get an xml like the one follows as ajax response.


Now i have to update an html page as in figure

One of the solution is to create checkboxes with name same as tagname in xml and iterate through the xml to check or uncheck the check box with name same as the current tag name depending upon value.

        var tagName=this.tagName;
        var val=$(this).text();
        else if(val==0){

Friday, February 3, 2012

code ignitor: Getting the error “Disallowed Key Characters”

Code Ignitor: Getting the error “Disallowed Key Characters” ?

   In Codeignitor, its usual for the developer getting the Error: "Disallowed Key Characters"
 This error used to drove newbies nuts. I am not sure about the reason and the fix provided by codeignitor help page not works some times[Most of the times from my experience]. It is also difficult to find what caused the error.

Here is solution that help in diagnosis of the problem.

In the core CI code in system/libraries is a file called input.php This small modification would show the actual data that caused the Problem.

Around line number 199

function _clean_input_keys($str)
if ( ! preg_match(“/^[a-z0-9:_\/-]+$/i”, $str))
exit(‘Disallowed Key Characters: ‘.$str);
// The variable $str was added to display the data in question.
return $str;

jQuery: exclude $(this) from selector

I have a set of text boxes and i want to check for duplication of set values in any of the text box. ie, no text box should contain a value that is entered in any other.

<form method="post" action="" onsubmit="return validate()">
                         <input type="textkbox" name="priority[]" />

                         <input type="textkbox" name="priority[]" />

                         <input type="textkbox" name="priority[]" />

                         <input type="textkbox" name="priority[]" />

                         <input type="textkbox" name="priority[]" />


var firstError='';
function validate(){
var mastrPriority=$(this);
var priority=$(this);
  seterrormessage(mastrPriority,'Duplicate Priority Values.');
seterrormessage(priority,'Duplicate Priority Values.');
alert("Priority Field should contain unique values.");

return false;
  return true;

function seterrormessage(field,msg){
var errorBox=$(field).parent().find('div.validationError').first();
  $(field).after('</br><div class="validationError">'+msg+'</a>');
The function validate() iterates through each text box and compare values of each box with all others except current one. The current text box is excluded from the set of text boxes using .not(this).