Wednesday, February 11, 2009

Python Type Conversions

int(x [,base])converts x
to an integer
long(x [,base])converts x
to a long integer
float(x)converts x
to a floating-point number
complex(real [,imag])creates a complex number
str(x)converts x
to a string representation
repr(x)converts x
to an expression string
eval(str)evaluates str and returns an object
tuple(s)converts a sequence object to a tuple
list(s)converts a sequence object to a list
chr(x)converts an integer to a character
unichr(x)converts an integer to a Unicode character
ord(c)converts a character to its integer value
hex(x)converts an integer to a hexadecimal string
oct(x)converts an integer to an octal string

totalRings = int(userInput)
//where totalRings and userInput are variables

Friday, February 6, 2009

Clone node issue in IE

Hi all,

I am writing after a long time.
If you are wondering why so long?
didnt I had anything worthwhile to type?
Yes, I didnt had anything to write, coz whatever I learnt in last few months its well documented all over internet.
Not to forget an important fact that during my free time last year i Played a lot with my Canon SLR-Like Camera.
You can check my photography @ Sinless Photography

But this Time again our big time sucker IE(Internet Explorer) showed his ugly face and delayed our work and entangled us in DOM herarchies.

IE Sucks it AGAIN.

cloneNode doesnt work for all elements in IE.
cloneNode doesnt work for all elements in IE.

My Problem.
I wanted to upload an image form without submitting the original form (in page1).
What I wanted to do:
1. Created a hidden form outside original form.
2. Copy / Clone input (type = file) element from original form to hidden Form.
3. Submit hidden form via JavaScript and view output in a frame (in page1).

What I did:
1. var clonedFileObject = document.forms['originalForm'].fileElement.cloneNode(true);
( where fileElement is input type = file element)
2. document.hiddenForm.appendChild(clonedFileObject);
3. hiddenForm.submit();

And What Happened.
var clonedFileObject = document.forms['originalForm'].fileElement.cloneNode(true);
Above statement worked perfectly fine in Firefox but in IE nothing happened.
No cloning was done and on form submission / image upload button All I could see was empty $_FILES array with error code = 4.

What all I tried:
1. hiddenForm.fileElement.value = originalForm.fileElement.value // didnt in FF either
2. Created a outer div and copied innerHTML of first div to hiddenforms div // didnt worked for input type file (didnt wasted much time either...should have worked)
3. Finally I did a shabby Patch work in my code which i really hated but in the given time limit and set conditions this was only I could think of.
var OriginalFileObj = document.getElementById('fileElement');
//this will remove fileElement from Original Form

var clonedFileObj = OriginalFileObj;
divObj.appendChild(OriginalFileObj); //restoring of original file object in original form
//if you dont do this there wont be any file object in original form

I am sure there would be other better ways to do the same.
If you are aware of it please add in comments so as others can benefit from you including me.