Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: data from forms

  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    data from forms

    is there any easy way to get data from a form?
    (so called datastream i guess)


    now im using this script (if anyone interested):
    PHP Code:
    function ff(f) {
        var 
    r=Array(),i=j=k=0,fl,t;
        if(
    f&&(f.tagName=='FORM')) {
            
    fl=f.length;
            for(
    i=0;i<fl;i++) {
                
    t=false;
                switch(
    f.elements[i].type) {
                    
    //checkbox:
                    
    case 'checkbox':
                    
    //radio:
                    
    case 'radio':
                        if(
    t=f.elements[i].checkedr[++k]=f.elements[i].name+'='+(f.elements[i].value?f.elements[i].value:1);
                        break;
                    
    //select:
                    
    case 'select':
                    case 
    'select-one':
                        
    r[++k]=f.elements[i].name+'='+f.elements[i][f.elements[i].selectedIndex].value;
                        
    t=true;
                        break;
                    case 
    'select-multiple':
                        for(
    j=0;j<f.elements[i].length;j++) {
                            if(
    f.elements[i].options[j].selectedIndex) {
                                
    r[++k]=f.elements[i].name+'='+f.elements[i].options[j].value;
                                
    t=true;
                            }
                        }
                        break;
                    default:
                        
    r[++k]=f.elements[i].name+'='+f.elements[i].value;
                        
    t=true;
                }
                
    report(encodeURI(r[k]));
                if(
    t)r[k]=(String(encodeURI(r[k])).split('&')).join('%26');
            }
            
    //report(r);
        
    }
        return 
    r;


    one more thing - when will we get something similar to php tag for javascript?
    Last edited by looka; 10-12-2005 at 09:57 PM.

  • #2
    New Coder
    Join Date
    Oct 2005
    Posts
    87
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Check out these scripts:

    http://www.codingforums.com/showthread.php?t=70051


    Hope they help.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no they are not exactly im looking for - im just looking for some i dont know - perhaps a property of form which returns a string to be send... or an array..

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm confused as to what you are wanting...

    In php, $_POST super-global array is an associative array of each named "input" element in a form...

    Or in javascript, document.myFormName.getElementsByTagName('tagName') will give you a collection of elements having said tagName (eg replace 'tagName' with 'input' to get all input elements). You could do this several times to collect all elements in a form into one array...

    Or you could start your own associative array onLoad and for each element's onChange, alter said array...

    Maybe if you could provide a more general goal as to what you eventually want to happen, we may be able to provide more help. Also your code is somewhat difficult to understand since we don't have interpretations for 1-2 letter abbreviations for your variables (I get that f = 'form', but r, k, etc. has me stumped); this goes back to us not knowing what you want to eventually have happen...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •