Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:11:42+00:00 2026-06-12T05:11:42+00:00

i have three input fields and i want to get there data when data

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:11:43+00:00Added an answer on June 12, 2026 at 5:11 am

    This is happening because you are initializing the field-#a inside 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:

    function getFielddata(field_id, field_value){
            if(field_value != ""){
                var field_1a = "",
                    field_2a = "",
                    field_4a = "";
    
                //alert(field_id+" "+field_value);
                if((field_id == "field-1a")){
                    field_1a = field_value;
                }
                else if((field_id == "field-2a")){
                    field_2a = field_value;
                }
                else if((field_id == "field-4a")){
                    field_4a = field_value;
                }
    
                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");
                   }
                  });
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a pile of input fields. I want to make
I have the hidden field: <input type=hidden class=deleted name=Deleted data-id=2 value=@Model.Deleted /> so there
$('#submit').click(function () { //Get the data from all the fields var name = $('input[name=name]');
I have many input fields in a form to post data to server side.
I have a webpage that has 3 file inputs. There are specific fields on
I have three input text boxes in my form. First one is teacher, second
suppose I have a simple container which have three element: <div> <span>hello world</span> <input
This is my input xml. The xml can have maximunm three nodes and minimum
I have div which has three buttons as, <div id=buttons> <input id=preview class=ButtonStyle type=submit
I have a enrollment form where users have to input there address. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.