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
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 />
Re: ajax post receives disabled value
Quote:
Originally Posted by
PeejAvery
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.
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?
Re: ajax post receives disabled value
Quote:
Originally Posted by
PeejAvery
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 :)