-
April 9th, 2009, 08:21 PM
#1
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
-
April 10th, 2009, 09:31 AM
#2
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.
-
April 12th, 2009, 08:25 PM
#3
Re: ajax post receives disabled value
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.
-
April 13th, 2009, 06:28 AM
#4
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.
-
April 14th, 2009, 07:49 PM
#5
Re: ajax post receives disabled value
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|