Hi,
This is ram.
I am developing a page(usereg.jsp ) with two textboxes one for username and another for email. Since i am using this page in main.jsp using Ajax, I am removing the body part in usereg.jsp.
Now i need to focus the cursor in first textbox of usereg.jsp. Since there is no body tag in this jsp i cannot call onload="documen t.formname.text boxname.focus() ".
But i need the focus in textbox when i call this page in main.jsp.
Even i have tried to focus the texbox in usereg.jsp by writing the seperate java script in this page. When i execute just this page(usereg.jsp ) the problem of focusing text box is solved,,
But when i call this page in main.jsp along with the java script i wrote, the focus is not reflecting.
Please suggest me where am i going wrong..
my mailid is: ****
33 3983 acoder 16,027
Recognized Expert Moderator MVP
If you are using Ajax, use the onreadystatecha nge event handler. Once the value is 4, you can call a function which deals with the response so include the focus code in that function.
I'm having the same problem but tried doing the focus in the function and it still doesn't work. Here's my javascript : - function doStuff() {
-
recn=document.getElementById('recno').value;
-
str = "moreStuff.php?recn="+recn;
-
http.open("GET", str, true);
-
http.onreadystatechange = handleHttpResponse;
-
http.send(null);
-
recno.focus();
-
}
Is this the wrong place to call for focus, or do I have the call syntax wrong?
pbmods 5,821
Recognized Expert Expert
Is this the wrong place to call for focus, or do I have the call syntax wrong?
The first 'A' in AJAX stands for 'Asynchronous'. In other words, handleHttpRespo nse won't get executed until your AJAX request returns. However, your script will continue to evaluate code until the request returns.
So when you put recno.focus() inside of doStuff: -
http.send(null);
-
recno.focus();
-
}
-
recno.focus() gets evaluated immediately after http.send gets executed, regardless of whether or (more likely) not the http request has returned.
What you want to do instead is to include recno.focus() inside of handleHttpRespo nse, so that it doesn't get called until your AJAX call returns.
[EDIT:
E.g.: -
function handleHttpResponse(response) {
-
.
-
.
-
.
-
// recno is a global variable, right?
-
recno.focus();
-
}
-
]
The first 'A' in AJAX stands for 'Asynchronous'. In other words, handleHttpRespo nse won't get executed until your AJAX request returns. However, your script will continue to evaluate code until the request returns.
So when you put recno.focus() inside of doStuff:
recno.focus() gets evaluated immediately after http.send gets executed, regardless of whether or (more likely) not the http request has returned.
What you want to do instead is to include recno.focus() inside of handleHttpRespo nse, so that it doesn't get called until your AJAX call returns.
[EDIT:
E.g.: -
function handleHttpResponse(response) {
-
.
-
.
-
.
-
// recno is a global variable, right?
-
recno.focus();
-
}
-
]
Hi, thanks for your help. But the problem is I have the handleHttpRespo nse code being called by many functions and only want the focus executed in one of them.
Recno is a field in a form, with different fuctions being called depending on which buttons the user clicks.
Basically, I have an accounts receivable app that includes searches by various fields, and when a particular set of records is chosen I have controls for fwd/back and go directly to a record in the set. It's that "goto" box containing the current record number (recno) that I'd like to focus, but only if a search is being done. They can type directly into the box to choose a record. Sorry I can't put it online right now because I wouldn't want some of it available to the public. But there's an identical (exept for no AJAX) search at This Link .
pbmods 5,821
Recognized Expert Expert
But the problem is I have the handleHttpRespo nse code being called by many functions and only want the focus executed in one of them.
You could use a different callback for each AJAX call.
E.g., -
function initAjax(url, callback) {
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
-
function doStuff() {
-
var recno = document.getElementById('recno');
-
-
initAjax("moreStuff.php?recno=" + recno.value, function(response) {
-
.
-
.
-
.
-
recno.focus();
-
});
-
}
-
When initAjax gets called, you create an anonymous function that, (presumably) among other things, calls recno.focus(), and thanks to JavaScript's magical scope implementation, anything declared in doStuff is available to your callback function.
If you wanted to make another AJAX call, but you wanted to do other stuff when the request returned, you'd do this: -
function doOtherStuff() {
-
initAjax('yetMoreStuff.php?you=get&the=idea', function(response) {
-
.
-
.
-
.
-
});
-
}
-
[EDIT: Recno. What a great name. Come here, Recno! Here, boy! That's a GOOD boy, Recno! Who wants a treat? Does Recno want a treat? Awww what a cute widdle puppy!]
You could use a different callback for each AJAX call.
E.g., -
function initAjax(url, callback) {
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
-
function doStuff() {
-
var recno = document.getElementById('recno');
-
-
initAjax("moreStuff.php?recno=" + recno.value, function(response) {
-
.
-
.
-
.
-
recno.focus();
-
});
-
}
-
When initAjax gets called, you create an anonymous function that, (presumably) among other things, calls recno.focus(), and thanks to JavaScript's magical scope implementation, anything declared in doStuff is available to your callback function.
If you wanted to make another AJAX call, but you wanted to do other stuff when the request returned, you'd do this: -
function doOtherStuff() {
-
initAjax('yetMoreStuff.php?you=get&the=idea', function(response) {
-
.
-
.
-
.
-
});
-
}
-
[EDIT: Recno. What a great name. Come here, Recno! Here, boy! That's a GOOD boy, Recno! Who wants a treat? Does Recno want a treat? Awww what a cute widdle puppy!]
Heck, I though it sounded more like an auto parts store ;-)
Anyway, getting late and I'll see if I can try that tomorrow. Thanks!
I must have something messed up, because now the page won't work at all (shows blank). Here's what I've got: - function initAjax(url, callback) {
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
-
function doStuff() {
-
recn=document.getElementById('recno').value;
-
initAjax("moreStuff.php?recn="+recn, function(response) {
-
http.open("GET", str, true);
-
http.onreadystatechange = handleHttpResponse;
-
http.send(null);
-
recno.focus();
-
});
-
}
Was I supposed to put something else where you have "function(respo nse)"? Not sure what should go there.
Worked on it some and have this now: - function initAjax(url, callback) {
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
function doStuff() {
-
recn=document.getElementById('recno').value;
-
initAjax("moreStuff.php?recn="+recn, function response(){
-
http.open("GET", str, true);
-
http.onreadystatechange = handleHttpResponse;
-
http.send(null);
-
recno.focus();
-
});
-
}
-
But now it won't let me change the record number in the box at all, and still doesn't focus.
pbmods 5,821
Recognized Expert Expert - function initAjax(url, callback) {
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
function doStuff() {
-
recn=document.getElementById('recno').value;
-
initAjax("moreStuff.php?recn="+recn, function response() {
-
recno.focus();
-
});
-
}
-
Callback is what initAjax executes when http.onreadysta techange fires, so the anonymous function should only contain what you want to do when your Ajax call returns.
Looking at the code (I've got my AJAX calls so deeply encapsulated, I've forgotten what a basic xmlHttpRequest call looks like), I think the problem is that http is a global variable. You need to create a local variable inside initAjax and create a new xmlHttpRequest instance. - function initAjax(url, callback) {
-
var http = new XMLHttpRequest();
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
Otherwise, every time you call initAjax, http gets destroyed and re-assigned a new request.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Gill Smith |
last post by:
when the page is loaded I am using onload event at the client side and
setting the focus on the control(TextBox). However when the user clicks on
Clear ImageButton, I am clearing all the text boxes and the grid(previous
search result display) in the clicked event of the ImageButton at the server
side. How to set the focus on the TextBox again when the user clicks on the
Clear button.
-Gill
|
by: A.M |
last post by:
Hi,
Can I configure a TextBox to have focus and cursor on it when page gets
loaded?
Thanks,
Alan
|
by: Christian Ista |
last post by:
Hello,
I have 2 questions :
1. On an ASP.NET page I have several controls (5 TextBox, 1 Dropdown and 1
button)
Only the dropdown is AutoPostBack = true, the TextBox are SingleLine
When I execute the page, I fill in the textbox, I change the dropdown
selection, the page is reloaded no problem I see the textbox still fill in.
|
by: CLEAR-RCIC |
last post by:
Hi,
I'm having problems setting focus to a textbox on a web user contol on an
asp.net web page. The following script works on normal asp.net pages:
<script language="javascript">
function cmdButton1_Clicked()
{ document.all('txtInput1').focus();
return false;
}
|
by: Alex.Svetos |
last post by:
Hello,
I'm trying to get a popup to keep focus when it is re-clicked.
The script below is supposed to produce this exact behaviour,
however it doesn't work, at least on firefox 1.0.7 and moz 1.7.12
(linux kubuntu). It does work with konqueror.
It seems to work with firefox on windows but not with IE (not completly
sure though).
| |
by: DJTN |
last post by:
I have an IE web control on a form that rotates the stats of the call center
in it. When a new page is loaded it takes the focus away from the other
textboxes on the form, even if a user is typing in them.
Is there anyway to keep the control from getting focus?
|
by: zacware |
last post by:
I have an AJAX enabled page which contains a list of records out of a
database which are loaded into a div via an AJAX call.
If the user switches to another window, and comes back to this open
window later on, I want the list of records to be udpated when the
window is back in front
a simple onFocus doesn't work, as what happens is that if a button is
clicked on the window it causes the onfocus to fire as well
|
by: pablorp80 |
last post by:
Hello,
Here is what I need:
I need the focus and the cursor set to a textbox named txtGT, every time no matter if it is the first page load or whether it is a postback.
Here is the problem:
I am using AJAX and MasterPages as well as an update panel, the textbox is in a panel. I have tried to do it using different java scripts but I can't get it to work because I am not using asp forms, instead I am using Containers.
Here is my code:...
|
by: Mel |
last post by:
I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True. After
I type something in the first input entry and press the "Tab" key how
can I set the focus to the next box after the postback? Please help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |