mgmhicks
asked on
JavaScript doesnt execute before code finishes
I have a page that loads checks for a session variable and responds in the following way
Master.myTitle = "Inspection Charges Report"
GetDates()
If IsDate(hfBeginDate.Value) Then
If IsDate(hfBeginDate.Value) Then
If InspectionChargesReport() Then
Else
End If
Else
End If
Else
ClientScript.RegisterClien tScriptBlo ck(Me.GetT ype(), "ClientScript", "alert ('Invalid Begin Date') ", True)
End If
Private Sub GetDates()
Page.ClientScript.Register StartupScr ipt(Me.Get Type(), "Script", "jsInputBox();", True)
End Sub
So what I dont understand and what is happening is that the code continues after getdates() sub, before the actual javascript has done its function, which is to bring up 2 prompt boxes asking for the dates. How do I change my code to make it react the way I want and thats to get the dates before continuing. My issue is that I want to run a report that takes 2 variable and begin and enddate and I have to ask user for those dates before continuing. I really dont want to create a form just to enter 2 dates. The javascript program attached does work correctly, just not triggering when I need it to.
function jsInputBox() {
var mBegin = prompt("Enter Begin Date", "");
// return (mBegin);
var newBegin = document.getElementById("c tl00_Conte ntPlaceHol der1_hfBeg inDate");
newBegin.value = mBegin;
//var txtCont = document.getElementById('< %= Page.FindControl("ContentP laceHolder 1").FindCo ntrol("txt Content"). ClientID %>');
var mEnd = prompt("Enter End Date:", "");
// return (mEnd);
var newEnd = document.getElementById("c tl00_Conte ntPlaceHol der1_hfEnd Date");
newEnd.value = mEnd;
}
thanks
Master.myTitle = "Inspection Charges Report"
GetDates()
If IsDate(hfBeginDate.Value) Then
If IsDate(hfBeginDate.Value) Then
If InspectionChargesReport() Then
Else
End If
Else
End If
Else
ClientScript.RegisterClien
End If
Private Sub GetDates()
Page.ClientScript.Register
End Sub
So what I dont understand and what is happening is that the code continues after getdates() sub, before the actual javascript has done its function, which is to bring up 2 prompt boxes asking for the dates. How do I change my code to make it react the way I want and thats to get the dates before continuing. My issue is that I want to run a report that takes 2 variable and begin and enddate and I have to ask user for those dates before continuing. I really dont want to create a form just to enter 2 dates. The javascript program attached does work correctly, just not triggering when I need it to.
function jsInputBox() {
var mBegin = prompt("Enter Begin Date", "");
// return (mBegin);
var newBegin = document.getElementById("c
newBegin.value = mBegin;
//var txtCont = document.getElementById('<
var mEnd = prompt("Enter End Date:", "");
// return (mEnd);
var newEnd = document.getElementById("c
newEnd.value = mEnd;
}
thanks
What you need to understand is that anything client side would happen AFTER the response goes back to the client. That is after all the processing on the server side is finished and the page is rendered to the client. So your approach wont work.
Can you not add two textboxes on the page and a button where user puts the dates and presses the button and you do the further logic in that button?
ASKER
Yes, and your the expert. You've help me many times. Is that how you handle all your prompts for reports? I was kinda trying to avoid that. But if that is the best way to do things, then thats what I want to do.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, I wrote above code directly here, so there are some errors. See attached example.
PopUp.zip
PopUp.zip