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: ****
Feb 25 '07
33 3987
We've all been there. With time, all things pass :)
Yes, but now and then you need a little Ex-Lax to get things moving ;-)
Alrightey. Buckle down and forget everything you learned about JavaScript. Here we go.... -
function myFunc(x) { return x * 5; }
-
// Which is the same as:
-
// myFunc = new Function('x', 'return x * 5;');
-
-
alert(myFunc);
-
What happens here, keeping in mind that myFunc is a variable that stores a Function object?
So anything "new" creates a variable that holds a string, number, or function, right? So if I pass an empty function { } it's just like passing an empty string.
...
-
initAjax(url, new Function('response', ''));
-
You're actually creating a new anonymous function which takes one argument (response, which will store the returned object from your XMLHttpRequest call automatically [and you don't have to worry about it; just assume that it will]).
A little fuzzy on how that works but right now I'm happy to take your word for it.
Question: We used to do - http.onreadystatechange = http.responseText;;
-
instead of - http.onreadystatechange = callback;
-
. When do we do http.responseTe xt now?
Still no page load, so I started the old put alerts everywhere thing, and it seems to go through all the right motions, yet nothing is put out. I tried it also on a much simpler part of my app, a section in another frame that just puts out a "rate card" of values used in calculations for an invoice. It displays the numbers and takes any changes, only this and nothing more.
Yet no output. But it's small so I'll try and post the whole thing here: - theOutput = 'output';
-
function handleHttpResponse() {
-
if (http.readyState == 4) {
-
document.getElementById(theOutput).innerHTML = http.responseText;
-
}
-
}
-
-
function getHTTPObject() {
-
var xmlhttp;
-
/*@cc_on
-
@if (@_jscript_version >= 5)
-
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
-
catch (e) {
-
try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
-
catch (E) { xmlhttp = false; }
-
}
-
@else
-
xmlhttp = false;
-
@end @*/
-
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
-
try { xmlhttp = new XMLHttpRequest(); }
-
catch (e) { xmlhttp = false; }
-
}
-
return xmlhttp;
-
}
-
-
function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
/////////////////////////////////////////////////////////////////////////////////
-
function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function response(){ });
-
}
-
-
function rChange(theField) {
-
fldnam=document.getElementById(theField).name;
-
fldval=document.getElementById(theField).value;
-
url = 'Rfunc.php?fldn='+fldnam+'&fldv='+fldval;
-
initAjax(url, function response(){ });
-
}
-
-
function rReport() {
-
url = 'Rfunc.php?report=recvbls';
-
initAjax(url, function response(){ });
-
}
Interesting: - function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function response(){ document.getElementById(theOutput).innerHTML = http.responseText; });
-
}
puts out nothing but: - function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function response(){ document.getElementById(theOutput).innerHTML = 'blah'; });
-
}
puts out "blah". Looks like we just aren't putting anything into ...innerHTML, because by the time we get to that statement the responseText is gone.
pbmods 5,821
Recognized Expert Expert
Go back and reread my last post.
pbmods 5,821
Recognized Expert Expert
So anything "new" creates a variable that holds a string, number, or function, right? So if I pass an empty function { } it's just like passing an empty string.
Basically, considering that when you pass an empty string, you're actually passing an instance of the String class without a value: -
doSomething('') === doSomething(new String(''));
-
doSomething(function() {}) === doSomething(new Function('', ''));
-
Question: We used to do - http.onreadystatechange = http.responseText;;
-
instead of - http.onreadystatechange = callback;
-
. When do we do http.responseTe xt now?
This is where that 'response' that you keep confusing for the function's name comes into play.
NOTE WHERE I PUT 'RESPONSE'. IT GOES INSIDE THE PARENTHESIS. -
initAjax(url, function (response) { eval(response.responseText); });
-
-
initAjax(url, new Function('response', 'eval(response.responseText);'));
-
The two statements do exactly the same thing. Remember that when http.onreadysta techange fires, it will automatically pass the result as the first parameter.
Fix your callbacks, and things should start working.
Oops, how did I do that with the ()? Fixed, added the eval, but still nothing. Tried this too and still nothing: - function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
-
function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function (response) {
-
eval(response.responseText);
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
});
-
}
Sorry I'm not catching on too well, maybe I need to go back and find some more beginner tutorials. But you've been a most patient teacher and I am very grateful for your help.
pbmods 5,821
Recognized Expert Expert
Oops, how did I do that with the ()? Fixed, added the eval, but still nothing. Tried this too and still nothing: - function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = callback;
-
http.send(null);
-
}
-
-
function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function (response) {
-
eval(response.responseText);
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
});
-
}
Ok, this is looking pretty good. But now we have a conflict: -
eval(response.responseText);
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
I used the 'eval' line just as an example, because I wasn't sure what you were getting back from your server-side script. But it looks like the script is sending HTML, not JavaScript. So you can go ahead and remove the 'eval' line (since eval(html code) will produce an error): - function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function (response) {
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
});
-
}
Sorry I'm not catching on too well, maybe I need to go back and find some more beginner tutorials. But you've been a most patient teacher and I am very grateful for your help.
I'm having fun, I promise. I know we all make typos occasionally (I happen to hold the world record for typos per hour, and I broke it three times last weeek^K^Kk). I apologize for my outburst.
- function getRatecard() {
-
url = "Rfunc.php";
-
initAjax(url, function (response) {
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
});
-
}
Done, but still nothing from "response.respo nseText;". Is it possible we need to wait for "http.readyStat e == 4"? I tried putting that around the "...innerHTML.. ." line but still nothing.
I'm having fun, I promise. I know we all make typos occasionally (I happen to hold the world record for typos per hour, and I broke it three times last weeek^K^Kk). I apologize for my outburst.
No prob. I know I can get on people's nerves with endless questions, especially when it's free edjamakashun. Thanks again.
pbmods 5,821
Recognized Expert Expert
Done, but still nothing from "response.respo nseText;". Is it possible we need to wait for "http.readyStat e == 4"?
Ooh. Good point. Alrightey. Let's add another layer of complexity to initAjax: -
function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = function(response) {
-
if(response.readyState == 4)
-
callback(response);
-
};
-
http.send(null);
-
}
-
We create a new anonymous function that checks for response's readyState (remember that response is set to the result from the AJAX call automatically when you assign it to http.onreadysta techange; http is undefined outside of initAjax, so we pass the response through callbacks). If it is 4, then we call callback and pass the response to it. Otherwise, we do nothing.
I tried putting that around the "...innerHTML.. ." line but still nothing.
Hm.
Try alerting your responseText to see if your script is sending anything back to you. -
initAjax(url, function (response) {
-
alert(response.responseText);
-
});
-
Try alerting your responseText to see if your script is sending anything back to you. -
initAjax(url, function (response) {
-
alert(response.responseText);
-
});
-
Tried this: - function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = function(response) {
-
if (response.readyState == 4) { callback(response); }
-
};
-
alert('ack');
-
http.send(null);
-
}
-
-
function getTestpage() {
-
url = "afunc.php";
-
initAjax(url, function (response) {
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
alert(response.responseText);
-
});
-
alert('done');
-
}
I get alerts for "ack" and "done" but not "response.respo nseText". Not even a blank alert, no alert at all.
pbmods 5,821
Recognized Expert Expert
Tried this: - function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = function(response) {
-
if (response.readyState == 4) { callback(response); }
-
};
-
alert('ack');
-
http.send(null);
-
}
-
-
function getTestpage() {
-
url = "afunc.php";
-
initAjax(url, function (response) {
-
document.getElementById(theOutput).innerHTML = response.responseText;
-
alert(response.responseText);
-
});
-
alert('done');
-
}
I get alerts for "ack" and "done" but not "response.respo nseText". Not even a blank alert, no alert at all.
Here's why you're not seeing anything:
heh
Because http actually *isn't* automatically assigning a value to response. I went back and looked at my AJAX frameworks, and it turns out that you have to manually do this.
Yeah. *sheepish grin*
So anyway, here's what initAjax *really* should look like (are we having fun yet?): - function initAjax(url, callback) {
-
var http = getHTTPObject();
-
http.open("GET", url, true);
-
http.onreadystatechange = function() {
-
if (http.readyState == 4) { callback(http); }
-
};
-
http.send(null);
-
}
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: 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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |