|
So, your theory is that you set focus to the drop down list, then when you click on the textbox the focus is lost on the drop down list and causes a postback? That doesn't make sense to me, as I just created a test page and I couldn't replicate that behavior:
<%@ Page Language="vb" AutoEventWireup="false" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ddlTest.Focus()
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test PostBack</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Postback: <%= Page.IsPostBack.ToString() %>
<br />
<asp:DropDownList runat="server" ID="ddlTest" AutoPostBack="true">
<asp:ListItem Text="Item 1" Value="1" />
<asp:ListItem Text="Item 2" Value="2" />
<asp:ListItem Text="Item 3" Value="3" />
</asp:DropDownList>
<br />
<asp:TextBox runat="server" />
</div>
</form>
</body>
</html>
The focus starts on the drop down list. When I click the textbox, there is no postback. Can you create a test page that replicates the behavior?
|
|
|
|
|
Hi, That is exactly right. It shouldn't postback just because it lost the focus. I too tested it and it doesn't happen in my test page.
I couldn't figure out what the issue is but when I debug our application it loads the page twice. And when the page got loaded I when I click on any where on the page the dropdown looses the focus and it is doing a post back.
It is very annoying to me. I am not sure loading the page twice, which I realized when I debugged the app is somehow may be causing this issue.
I am kind of exhausted with this issues as I couldn't figure what in the world is going on to cause the page load twice.
I really appreciate for replying to all my messages.
If I had any luck I will post it here.
Thanks again.
L
|
|
|
|
|
The other way I am thinking is to set the dropwdowns.Focus() some where in one of the the page life cycle events (init, Load, validate, Event, Render, Unload) but not in the same location where it is being set right now? Even then, no matter what by the time it loads the page the dropdownlist would get the focus?
Please provide if this way provides any solution to my issue.
|
|
|
|
|
Heh, this kind of thing is why I never liked ASP.
|
|
|
|
|
Ok I'm trying to learn this and I'm running into a problem and I'm not sure why... I'm going through a tutorial on tizag and I'm getting a error for the onChange event. This is the code:
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
function ajaxFunction(){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.myForm.time.value = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "serverTime.php", true);
ajaxRequest.send(null);
}
</script>
<form name='myForm'>
Name: <input type='text' onChange="ajaxFunction();" name='username' /> <br />
Time: <input type='text' name='time' />
</form>
</body>
</html>
the error message is "Object expected at JScript - myForm onchange function() (/IntranetSite/order.html:47)
Thanks in advance!!
|
|
|
|
|
Have you debugged? Once you have you will be able to find the issue easily.
I would use JQuery and do away with this mess of nested try/catch blocks
No comment
|
|
|
|
|
yes that is where I got the error message from (the debugger)...
I'm just trying to learn how to get a JavaScript app to work with a database and this was the first part of the tutorial. If you have any better ideas I'm open to them as I haven't invested too much into this one yet
Does onChange="ajaxFunction();" need to be single quote?
|
|
|
|
|
MacRaider4 wrote: Does onChange="ajaxFunction();" need to be single quote?
Wouldn't it be faster to test that theory yourself rather than ask if that's the solution and wait for an answer?
EOL
|
|
|
|
|
I tried it that way and it made no difference, but I was wondering as I would like to learn the "right way"... forgot to mention that in my reply sorry
|
|
|
|
|
I typically favor using double quotes, though single quotes would work too. When working with ASP.net, I find it easier to sometimes use single quotes, as binding often makes use of double quotes (and having double quotes inside double quotes can cause errors).
EOL
|
|
|
|
|
Coming from an application background this web stuff is a bit hard to get used to, but doesn't seem too bad all in all. Though it would be nice if you didn't have to go about things in a round about manner.
Back to the original issue, it seems like the function call wants something in the () however I don't have anything specified in the function it self so that doesn't make sense.
|
|
|
|
|
Ok I've found it... simple mistake I guess...
<script type="text/javascript">
vs
<script type="txt/javascript">
forgot the 'e' in text....
|
|
|
|
|
HTML attributes should be enclosed in double quotes, as it's part of the same family as XML. Most browsers will tolerate all sorts of bad markup but to do it right is to use doubles there. Quotes within Javascript can be either, as long as they are paired with the same type, and either is fine in any situation.
|
|
|
|
|
Well if double is the standard then I'll go with double. Thanks for the help!!
|
|
|
|
|
I created a PDF form from an excel file. I have everything figured out, except one of the fields in which I am able to round the answer up to the nearest integer, but I need to take it one step further and round it to the nearest 5 or 0. This is what I an using as my custom calculation script:
(Math.ceil(CourseHours/40) + " ");
I have just started learning javascript so I found this off of a website. If anyone could help I would certainly appreciate it. Thank you in advance.
|
|
|
|
|
Use
Math.round( n /5) * 5;
where n is the number you are looking to round off.
Imagination is the one weapon in the war against reality!!!
aniruddhaloya.blogspot.com
|
|
|
|
|
That did not work but looking at my email again, the entire script didn't paste. It is
(Math.ceil(CourseHours/40)+" ");
Sorry about that. Thanks much.
modified 15-Jan-12 20:43pm.
|
|
|
|
|
I guess your entire script is not there again...
Anyways... Math.ceil will always take it to next higher number whereas Math.round round it to the nearest integer. So you can choose as per your requirement.
From what I think you are looking to do is - You require (CourseHours/40) rounded to nearest 0 or 5... i.e. the number you eventually looking to round off is the output of - CourseHours/40...
So for my solution to work - 'n' should be substituted by - CourseHours/40
i.e
Math.ceil(CourseHours/40/5) * 5 or use Math.round as per your requirement.
I hope this helps.
Imagination is the one weapon in the war against reality!!!
aniruddhaloya.blogspot.com
|
|
|
|
|
It seems to work, but what I am finding is that, as most of the answers will be less than 1, it is rounding it to the nearest 0 or 5 in the thousandths when I need it to be no larger then hundreths. SO all I should have as the final answer is .15 or .35. Does that make sense?
|
|
|
|
|
You can try using "Number".toFixed(x) along with the existing solution for fixing that.
More info of your data set may help to find a better solution though
Imagination is the one weapon in the war against reality!!!
http://aniruddhaloya.blogspot.com
|
|
|
|
|
Hi,
Try Math.floor()
Thanks,
|
|
|
|
|
This is going to be my first JavaScript application as strict PHP doesn't seem like it's going to work. What I need to do is create a football pool square chart. I'm not looking for someone to develop it for me, just for some guidance as I want to learn what I'm doing. From what I've read I'm going to need to use PHP to do the database calls but I'm not sure how to get that info back to JavaScript.
Looking for some ideas... thanks!!!
|
|
|
|
|
I found an ajax example but can't get it to work... started a new thread for that.
|
|
|
|
|
Hi everyone!
I am currently working on a project to make a web site W3C compliant. The site currently uses a lot of instances of document.all , document.form.object and form.object notations. I am mostly concerned about formname.objectname style. I have been trying to search DOM specs on www.w3.org[^] and google but couldn't find any specific information related to this type of usage. So my question is if anyone knows of the place (preferrably official) that says whether this usage is allowed and is cross-browser or should I replace it with document.getElementById ?
Thanks in advance!
|
|
|
|
|
Can you not use jQuery[^]? Won't that give you full cross browser functionality with more compact/consistent notation and W3C compliance? (Not 100% about the compliance - you'd need to check that).
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|