473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

JavaScript Form Field Value Update Dilemma

Although I'm making an ajax call, this is really a javascript question
(although it could be even more of an HTML or DOM question... not
exactly sure)

I'm doing an ajax call to a remote php file... it returns a value fine,
and even enters a value into a text field on my form. The problem is,
right after the function call to the ajax function, I do an alert of
what the field value is, and it doesn't recognize the field value has
been changed.

Two caveats:

1 - It will recognize the last call's change
(if I run it a 2nd time, it'll see the 1st call changes)
onBlur="ajaxCall(document.form1);alert(document.fo rm1.ajaxField.value);">

2 - It'll recognize the current call's change if I set a 2 second
timeout
onBlur="ajaxCall(document.form1);setTimeout('check Fields(document.form1)',2000);">

It seems, although I can see the text field getting updated,
programmatically speaking, it isn't reflecting it until everything is
done... including any alerts and such.

It's weird seeing the empty alert popup, when I can see the value in
the text field underneath it.

Keith D Commiskey
http://kdcinfo.com

Jan 7 '07 #1
6 2911
KDCinfo wrote:
1 - It will recognize the last call's change
(if I run it a 2nd time, it'll see the 1st call changes)
onBlur="ajaxCall(document.form1);alert(document.fo rm1.ajaxField.value);">

2 - It'll recognize the current call's change if I set a 2 second
timeout
onBlur="ajaxCall(document.form1);setTimeout('check Fields(document.form1)',2000);">
Well what exactly does the function ajaxCall do? If it does an
asynchronous request to the server setting up some event handler
processing the response to the request then it is quite normal that the
change has not been done after the call to the function as the function
just starts the requests and is then finished. When the response arrives
the browser calls the event handler. If any script runs before the
response arrives and has been processed then you can't expect to have
any change.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 7 '07 #2
Martin Honnen wrote:
Well what exactly does the function ajaxCall do? If it does an
asynchronous request to the server setting up some event handler
processing the response to the request then it is quite normal that the
change has not been done after the call to the function as the function
just starts the requests and is then finished. When the response arrives
the browser calls the event handler. If any script runs before the
response arrives and has been processed then you can't expect to have
any change.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Thanks Martin,

I believe you're correct in that it is an "asynchronous request to the
server"

My ajax call is this:
http.open("GET", url + '?param1='+escape(variable), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);

The php file then executes a mysql query, and echoes what I need. Then,
back in the main file, that echo is then written to the document form
field (which does display it).

So, if as you said, that php file is sent to execute, but the main file
carries on at the same time, that would certainly make sense. I tried
putting in an onChange event handler on the field being updated, but
apparently that doesn't apply to programmatical changes to the field.

I'm guessing a ittle delay window with a progress bar (for a generic
count of say 2 seconds) might be suitable, hoping the database doesn't
hiccup and require 3 seconds at some point...

Perhaps there's a way for the remote php file to notify the local file
that it's done?
Perhaps there's a way that field can detect it has been updated?
Perhaps a non-asynchronous request (a linear/sequential request) - if
that exists or is possible?

P.S. This is my first ajax call, so its 'clicking' more and more as I
progress :)

Thanks again!

Keith D Commiskey
http://kdcinfo.com
http://giftsforyou.biz

Jan 7 '07 #3
KDCinfo wrote:
Perhaps there's a way for the remote php file to notify the local file
that it's done?
Perhaps there's a way that field can detect it has been updated?
Perhaps a non-asynchronous request (a linear/sequential request) - if
that exists or is possible?
Never mind my thought about synchronous requests:

Synchronous Requests == BAD | Ajax Blog
http://ajaxblog.com/archives/2005/05...s-requests-bad

Keith D Commiskey
http://kdcinfo.com
http://giftsforyou.biz

Jan 8 '07 #4
KDCinfo wrote:
[...]
So, if as you said, that php file is sent to execute, but the main file
carries on at the same time, that would certainly make sense. I tried
putting in an onChange event handler on the field being updated, but
apparently that doesn't apply to programmatical changes to the field.
Onchange fires when the field loses focus if the value has changed from
when it got focus - it is likely in this case that the field will lose
focus before the change occurs. In general, onchange is one of the
less reliable events to use.
>
I'm guessing a ittle delay window with a progress bar (for a generic
count of say 2 seconds) might be suitable, hoping the database doesn't
hiccup and require 3 seconds at some point...
A progress bar might be OK, but guessing the time to display it isn't.

Usually just a 'loading...' graphic is used since it is difficult to
give meaningful feedback on the request's progress.
>
Perhaps there's a way for the remote php file to notify the local file
that it's done?
Use one of the (many) AJAX libraries that provide a callback when the
call has completed. Try AjaxToolbox:

<URL: http://www.ajaxtoolbox.com/ >

which provides things like a callback and activity monitoring (for your
progress bar).

Perhaps there's a way that field can detect it has been updated?
Perhaps a non-asynchronous request (a linear/sequential request) - if
that exists or is possible?
A synchronous call defeats the purpose of AJAX, doesn't it? ;-) But
anyhow, you can submit synchronous requests if you want - see
AjaxToolbox above.
--
Rob

Jan 8 '07 #5
RobG said the following on 1/7/2007 8:32 PM:
KDCinfo wrote:
[...]
>So, if as you said, that php file is sent to execute, but the main file
carries on at the same time, that would certainly make sense. I tried
putting in an onChange event handler on the field being updated, but
apparently that doesn't apply to programmatical changes to the field.

Onchange fires when the field loses focus if the value has changed from
when it got focus -
value="some value"
user types in new value
user changes it back to "some value"

The value has been "changed from when it got focus" but onchange won't
fire :-)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 8 '07 #6
RobG wrote:
KDCinfo wrote:
[...]
Perhaps there's a way for the remote php file to notify the local file
that it's done?

Use one of the (many) AJAX libraries that provide a callback when the
call has completed. Try AjaxToolbox:

<URL: http://www.ajaxtoolbox.com/ >

which provides things like a callback and activity monitoring (for your
progress bar).
--
Rob
THANKS for that reference and link Rob! That is now the next step on my
AJAX journey.
Keith D Commiskey
http://kdcinfo.com
http://giftsforyou.biz

Jan 8 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Larry | last post by:
I have a form that submits some js created data through a formmail script. One field of the form is a text box for the person's name. I'd like the subject line of the resulting email to be "Some...
4
by: GavMc | last post by:
Hello I am new to internet programming and wonder if anyone can help me with this.... I am trying to pass a hidden field value on a form into another field on the form so that it can then be...
1
by: xenophon | last post by:
I add a Hidden form field to my asp.net page in the codebehind, the Value peoperty is set to 0 and EnableViewState is set to true. Then I add a LiteralControl with JavaScript that says to set the...
2
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
2
jayfrankland
by: jayfrankland | last post by:
Hello: I have a form called ApplicationFees that contains a field value called Project_Id. Within the page I also have an iframe. I need to get or request the Project_Id value from the...
2
by: Brave | last post by:
I'm hoping someone can help me with a small issue. I have an asp page that displays informaton from an Access database. I want to create a form that allows users to display only data that...
2
by: aravelli | last post by:
how can i get if the form field value is disbled by using a jsp <input type=text name="uid" value="aravelli" disabled/> if i use a jsp like String userid = request.getParameter("uid"); ...
2
by: Harmony504 | last post by:
I am passing a form field in JavaScript to a PHP function. The problem is when the parameter gets inside the PHP function the value is set to 1 when it should be a relative path to a file. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.