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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:10:01+00:00 2026-06-01T12:10:01+00:00

I know that there are more practical ways of going about what I’m trying

  • 0

I know that there are more practical ways of going about what I’m trying to accomplish here, but I need to stick to this model if it’s possible.

I’m trying to send values from multiple HTML text input fields to a Javascript function.
It works as expected on the first submission. Each time after when Ajax reloads the form into the container div, it sends the values of the original submission, not the updated values. How would I fix this?

This is where the call is made: (Resulting output from drawNewEvent.php displays within the Div tags)

<? $cal = $_POST['cal']; ?>
<button type="button" onClick="newEvent(<? echo $cal['KEY']; ?>)">Add Event</button>

<div id="container">

<!--Form goes here-->

</div>

This is the Ajax function I’m using:

function newEvent(calID){
    var xmlhttp;
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }


    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("container").innerHTML=xmlhttp.responseText;
        }
    }

    xmlhttp.open("POST","cal/draw/drawNewEvent.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("calID="+calID);
}

drawNewEvent.php:

<? $calID = $_POST['calID']; ?>
<h1> Add Event to <? echo $calID;?></h1>
<table border="1"><tr><td>
<br>
<table>
<tr>
<td>Event name:</td><td><input name="name" type="text" id="aname" size="32" maxlength="40" /></td>
</tr><tr>
<td>Date:</td><td><input name="date" type="text" id="date" maxlength="10" value="<?php echo date('Y-m-d'); ?>"/> (YYYY-MM-DD)</td>
</tr><tr>
<?php $hour = date('H'); $hour -= 4;?>
<td>Starting Time:</td><td><input name="sTime" type="text" id="sTime" maxlength="8" value="<?php echo $hour.date(':i'); ?>"/> (HH:MM)</td>
</tr><tr>
<td>Ending Time:</td><td><input name="eTime" type="text" id="eTime" maxlength="8" value="<?php echo ($hour+1).date(':i'); ?>"/> (HH:MM)</td>
</tr>
<tr>
<td>Location:</td><td><input name="location" type="text" id="alocation" size="32" /></td>
</tr>
<tr>
<td>Notes:</td><td><textarea name="notes" id="notes"  rows="10" cols="30"/></textarea></td>
</tr>
</table>
<button type="button" name="add" 
onClick="addEvent(aname.value, date.value, sTime.value, eTime.value, alocation.value, notes.value, <?php echo $calID ?>)">Add Event </button>
</td></tr></table>

The function called just displays the given input:

function addEvent(name, date, sTime, eTime, location, notes, calID){
    alert("name: "+name + "\nDate: " + date + "\nTime: " + sTime + "-" + eTime + "\n Location: " + location + "\n Notes: " + notes + "\n CalID = " + calID);
}
  • 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-01T12:10:03+00:00Added an answer on June 1, 2026 at 12:10 pm

    Well, your calID is always the same (is it supposed to be?). You are sending an ajax request with the same parameters in the URL and most likely the second time around you are getting a cached response, so the second ajax request is never run through the server. I would suggest to avoid caching by using a random, or changing variable. For instance:

    var d = new Date();
    var n = d.getTime();
    xmlhttp.open("POST","cal/draw/drawNewEvent.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("calID="+calID+"&random="+n);
    

    Now your ajax request is seen by the browser as a different request and is not being returned from cache. Let’s debug from here. How is your script behaving now?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there must be dozens of correct ways to do this, but
I know that there are lot's of questons on this, but all seem to
I know that there are others posts with solutions on the site but i
I know that there are lots of examples out there on this, but they
I know that there can be multiple values for an email, but I'm not
I know that there are many Delphi database related questions available, but I'm considering
Wish to know more about the practical differences between init and initWithNibName . SO
I know that there are some threads have a similar issue with this thread.
I know that there are currently questions on SO already pertaining to saving jQuery
I know that there is an allocator for user applications than handles lots of

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.