CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Posts
    141

    ajax post receives disabled value

    hi

    this is something new I learned this week, and I hope someone can shed some light about it. i'm wondering why my ajax post receives disabled value? traditionally it shouldn't, right?

    here's my code snippet

    this is the page which sends the data
    Code:
    <form name='submitMyForm' method='POST'>
    <input type=text name='cicak' value='blablabla' disabled='true'>
    <input type=button value='Submit All' onClick='saveAll(submitMyForm);'></form>
    and here's the function saveAll()

    Code:
    function saveAll(getForm){	
    
    	xmlHttp = GetXMLHttpObject()	
    	
    	if (xmlHttp==null){
    		alert ("Browser doesn't support HTTP request")
    		return
    	}
    	
    	var url = "saveExpenses.php";
    	var params = createQuery(getForm);
    	
    	xmlHttp.onreadystatechange=stateChanged
    	xmlHttp.open("POST",url,true)
    	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	xmlHttp.setRequestHeader("Content-length", params.length);
    	xmlHttp.setRequestHeader("Connection", "close");
    	xmlHttp.send(params);			
    	
    }
    and here's the saveExpenses.php

    Code:
    $cicak = $_POST['cicak'];
    echo "cicak: ".$cicak;
    it displays the value in 'cicak', which is 'blablabla', although the field 'cicak' is disabled. how do I make it work just like normal submit form, which doesn't send/receive disabled input.

    any help is greatly appreciated. thank you very much

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: ajax post receives disabled value

    There is no true value for the disabled attribute.

    Code:
    <input type="text" name="text1" value="" disabled="disabled" />
    Or...shorter...

    Code:
    <input type="text" name="text1" value="" disabled />
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2005
    Posts
    141

    Re: ajax post receives disabled value

    Quote Originally Posted by PeejAvery View Post
    There is no true value for the disabled attribute.

    Code:
    <input type="text" name="text1" value="" disabled="disabled" />
    Or...shorter...

    Code:
    <input type="text" name="text1" value="" disabled />

    hmm.. i tried your methods but still, the disabled value is POSTED.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: ajax post receives disabled value

    I would guess that the problem is in how you are obtaining your data from the inputs. What does the createQuery() method look like?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jul 2005
    Posts
    141

    Re: ajax post receives disabled value

    Quote Originally Posted by PeejAvery View Post
    I would guess that the problem is in how you are obtaining your data from the inputs. What does the createQuery() method look like?
    yup2.. I figured out that's the problem come from. btw here's my fixed createQuery which is now working as I needed. the original one doesn't have the line if (!(elements[i].disabled))

    Code:
    function createQuery(form)
    {
        var elements = form.elements;
        var pairs = new Array();
    
        for (var i = 0; i < elements.length; i++) {
        
            if (!(elements[i].disabled)){ //added to fix the sending disabled value problem
                if ((name = elements[i].name) && (value = elements[i].value))
                pairs.push(name + "=" + encodeURIComponent(value));
            }
    
            
        }
    
        return (pairs.join("&"));
    }
    thanks a lot for helping

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured