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 8376063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:20:10+00:00 2026-06-09T15:20:10+00:00

I want to load form data and send it to the sever then chart

  • 0

I want to load form data and send it to the sever then chart with the returned data. It works fine if the form’s input field have default data and I comment

//$("button").click(function(){

I get no chart all if the default text fields are empty. I tried different ways but still I wont get it load from the form by clicking a button. I am stuck for 2 days now. Please, help. Thanks in advance. Here is the code

<script type="text/javascript">
var chart = null;
var dataString = [];
$(document).ready(function() {
    $("button").click(function() {
        $(function() {
            var city1 = $("#city1").val();
            var city2 = $("#city2").val();
            dataString = {
                city1: city1,
                city2: city2
            };

            requestData();
        });
    });

    function requestData() {
        $.ajax({
            url: 'array.php',
            type: 'POST',
            data: dataString,
            success: function(point) {
                var chartSeriesData = [];
                var chartCategory = [];
                $.each(point, function(i, item) {
                    var series_name = item.name;
                    var series_data = item.data2;
                    var cagory = series_name;

                    var series = {
                        name: series_name,
                        data: item.data2
                    };
                    chartSeriesData.push(series);
                    chartCategory.push(series_name);
                });
                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'container',
                        defaultSeriesType: 'column',
                    },
                    title: {
                        text: 'Real time data from database'
                    },
                    xAxis: {
                        categories: chartCategory
                    },
                    yAxis: {
                        minPadding: 0.1,
                        maxPadding: 0.1,
                        title: {
                            text: 'Value',
                            margin: 40
                        }
                    },
                    series: chartSeriesData
                });
            },
            cache: false
        });
    }
});​
</script>

Here is the body section

<body>

<div id="container" style="min-width: 200px; height: 400px; margin: 0 auto"></div>

<div id="city_form">
  <form name="contact" action="" method="post">
      <label for="city1" id="city1_label">First city</label>
      <input type="text" name="city1" id="city1" size="30" value="Amsterdam" />


      <label for="city2" id="email_label">Second city</label>
      <input type="text" name="city2" id="city2" size="30" value="London" />
      <button>Click me</button> 
  </form>
</div>

</body>
</html> 
  • 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-09T15:20:12+00:00Added an answer on June 9, 2026 at 3:20 pm

    You are doing a bunch of things incorrectly here, one as pointed out by wirey, other you have to prevent the form submission on click of the button. Eh? When you click the submit button, its default action is to submit the form and take you to the action page. You do have an added eventListener attached, which makes this ajax call and then plots the chart, but the button will still perform its default action, viz. take you to the action page, which in you case is the same page, so you don’t even realize that such a thing happened, you may have noticed a flicker or page reload?

    jQuery allows preventing this default action by calling the preventDefault() method on your event object, which gets passed to you event listener as the 1st argument. You can read more about it here http://api.jquery.com/event.preventDefault/
    Try this and let us know if it helped.

    HTML

    <div id="city_form">
      <form name="contact" action="" method="post">
          <label for="city1" id="city1_label">First city</label>
          <input type="text" name="city1" id="city1" size="30" value="Amsterdam" />
    
    
          <label for="city2" id="email_label">Second city</label>
          <input type="text" name="city2" id="city2" size="30" value="London" />
          <button id="btnGet">Click me</button>
      </form>
    </div>
    

    JS

    $("#btnGet").click(function(evt) {
        evt.preventDefault();
        var city1 = $("#city1").val();
        var city2 = $("#city2").val();
        var dataString = {
            city1: city1,
            city2: city2
        };
        requestData(dataString);
    
    });
    

    jsFiddle @ http://jsfiddle.net/jugal/V5zt9/6/

    • 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 DataGridView and I want to load data from
I want to load the form fields using json data. I am using extjs
I want to load data from MySql database to a HTTP form When I
<form method=post action=load_statements.php?action=load id=loadForm enctype=multipart/form-data> that is my form, which looks fine to me.
this is the method I want to send data to it function get_lesson($reshte,$poodeman){ $this->load->model('dropdown_model');
I want to load json data in form of a tree into Backbone Collection.
I have this button with which I want to send data back to the
I want to run a console application (eg app.exe) from a windows form load
Hi I want to set opacity for a form in page load. I try
I am using jquery validation plugin to validate my form. I have one field

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.