i have three input fields and i want to get there data when data is entered. Though it works fine but still it shows this error in firebug.
Hope there will be a better way to do this.
ERROR showing in firbug :
ReferenceError: field_2a is not defined
[Break On This Error]
...ataString = 'field-1a='+ field_1a + '&field-2a=' + field_2a + '&field-4a=' + fie...
My script is as under :
<script>
function getFielddata(field_id, field_value){
if(field_value != ""){
//alert(field_id+" "+field_value);
if(field_id == "field-1a"){
if(field_value){
field_1a = field_value;
}
else
{
field_1a = "";
}
}
else if(field_id == "field-2a"){
if(field_value){
field_2a = field_value;
}
else
{
field_2a = "";
}
}
else if(field_id == "field-4a"){
if(field_value){
field_4a = field_value;
}
else
{
field_4a = "";
}
}
var dataString = 'field-1a='+ field_1a + '&field-2a=' + field_2a + '&field-4a=' + field_4a;
//alert(dataString); return false;
$.ajax({
type: 'POST',
url: 'get_query.php',
data: dataString,
success: function(data) {
//$("#SuburbDiv").html(data);
alert("data inserted successfully");
}
});
}
}
</script>
and i am saving it onChange event like this :
<input type="text" id="field-2a" onChange="getFielddata(this.id, this.value)"/>
and Help ???
Note : There is no submit button
This is happening because you are initializing the
field-#ainside the if statements that never get executed, then you try to access them. I also have a feeling that these variables have to be local to the function. Try this: