|
-
Nov 21st, 2002, 02:00 PM
#1
Thread Starter
Frenzied Member
populating textbox without postback
I'm using this code to place a date in a textbox2 after the user has selected the begin date for textbox1. It works fine, but I can only get it to work after the page has been postedback. Can I use some java code, so the textbox will populate as soon as the date is placed in the first textbox?
The user is selecting the date from a popup calendar which is on another page.
txtIntDisEndDate.Text = DateAdd(DateInterval.Day, 1, CDate(txtBidOpenDate.Text))
-
Nov 21st, 2002, 02:34 PM
#2
Hyperactive Member
sure, use some javascript something like the following:
Code:
var yourTextBox = document.getElementById("YourTextBoxId");
if (yourTextBox)
yourTextBox.value = "some new value";
-
Nov 21st, 2002, 02:59 PM
#3
Thread Starter
Frenzied Member
now does this go into a <script> tag? If so how will it be called?
-
Nov 21st, 2002, 04:55 PM
#4
Hyperactive Member
Well it depends on how you get values back from your calendar. How do you get the value back from your calendar?
-
Nov 22nd, 2002, 08:12 AM
#5
Thread Starter
Frenzied Member
I'm using an anchor tag to open the calendar page:
<A style="Z-INDEX: 117; LEFT: 386px; POSITION: absolute; TOP: 422px" href="javascript:calendar_window=window.open('calendar.aspx?formname=_ctl0.txtBidOpenDate','calendar _window','width=250,height=225');calendar_window.focus()">Select
Date</A>
then onSelection change in the calendar, I fire off this event to return a querystring:
Public Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)
Dim strjscript as string = "<script language=""javascript"">"
strjscript = strjscript & "function SendBack() {"
strjscript = strjscript & "window.opener." & Httpcontext.Current.Request.Querystring("formname") & ".value = '" & Calendar1.SelectedDate & "';window.close();"
strjscript = strjscript & "}</script" & ">"
Literal1.text = strjscript
End Sub
-
Nov 22nd, 2002, 02:03 PM
#6
Hyperactive Member
this worked out pretty well:
calendar.aspx:
Code:
<script runat="server" language="vb">
Sub Cal_SelectionChanged ( ByVal sender As Object , ByVal e As System.EventArgs)
Dim sJscript As String = ""
sJscript &= "<script>SendBack()"
sJscript &= "<" & "/script>"
CloseMeCode.Text = sJscript
End Sub
</script>
<html>
<head>
<script language=javascript>
function SendBack(){
var parentWin = window.opener;
var targetCtlName = "<%= Request("TargetCtl") %>";
var targetCtl = null;
if (parentWin){
targetCtl = parentWin.document.getElementById(targetCtlName);
if (targetCtl){
targetCtl.value = "<%= Cal.SelectedDate.ToShortDateString() %>";
targetCtl.fireEvent("onchange");
window.close();
}
}
else
alert("Parent window not found...");
}
</script>
</head>
<body>
<form id="calendar" runat="server">
<asp:Literal
ID="CloseMeCode"
Runat="server"/>
<asp:Calendar
ID="Cal"
OnSelectionChanged="Cal_SelectionChanged"
Runat="server"/>
</form>
</body>
</html>
main page dateTest.aspx:
Code:
<html>
<head>
<title>dateTest</title>
<script language="javascript">
function GrabDate(){
var oCal = window.open('calendar.aspx?TargetCtl=MyTextBox','','height=250,width=300');
}
function SetOtherDate(){
var otherDate = document.getElementById("MyTextBox2");
if (otherDate){
var date1 = new Date(document.getElementById("MyTextBox").value);
date1.setDate(date1.getDate() + 7);
otherDate.value = (date1.getMonth()+1) + "/" +
date1.getDate() + "/" +
date1.getFullYear();
}
}
</script>
</head>
<body>
<form id="dateTest" method="post" runat="server">
<asp:TextBox
ID="MyTextBox"
onChange="SetOtherDate()"
Runat="server"/>
<a href="#" onClick="GrabDate()">Get Date</a><br/>
<asp:TextBox
ID="MyTextBox2"
Runat="server"/>
</form>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|