Posted: 4/6/2010
Hello Experts,There is one dropdownlist and one Textbox. When I select an index of dropdownlist, the current time fill in textbox.Here is my code:-
<table> <tr> <td><asp:DropDownList ID="ddlTest" runat="server" onselectedindexchanged="ddlTest_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem>one</asp:ListItem> <asp:ListItem>two</asp:ListItem> <asp:ListItem>three</asp:ListItem> </asp:DropDownList></td> <td><asp:TextBox ID="txtTest" runat="server"></asp:TextBox></td> </tr> </table>
protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e) { txtTest.Text = DateTime.Now.TimeOfDay.ToString().Substring(0, 5); }
It working fine with postback.But i want to do this without postback(javascript or jQuery).can anyone tell me how can I do this on client side?Thanks in advance:)
Posted: 4/8/2010
Hi,
try this code
<SCRIPT LANGUAGE="javascript">
<!--
function onchange()
{
var d = new Date();
var curr_hour = d.getHours();
var curr_min = d.getMinutes();
var curr_seg = d.getSeconds();
var time = curr_hour + " : " + curr_min + " : " + curr_seg;
//jquery sentence
$('#txt').val(time);
return true;
}
<table> <tr> <td><asp:DropDownList ID="drp" runat="server" onchange ="javascript:onchange()" > <asp:ListItem>Select</asp:ListItem> <asp:ListItem>one</asp:ListItem> <asp:ListItem>two</asp:ListItem> <asp:ListItem>three</asp:ListItem> </asp:DropDownList></td> <td><asp:TextBox ID="txt" runat="server"></asp:TextBox></td> </tr> </table>
good luck
Posted: 4/17/2010
thanks irokhe.
irokhes said: var d = new Date();var curr_hour = d.getHours();var curr_min = d.getMinutes();var curr_seg = d.getSeconds();var time = curr_hour + " : " + curr_min + " : " + curr_seg;
Irokhes, this will give client side time ie of clients machine . If we need the time with respect to server you know it won't work. Yes if orignal poster has the requirement to go with the client side time then you are right .
Posted: 4/19/2010
raghav_khunger said: irokhes said: var d = new Date();var curr_hour = d.getHours();var curr_min = d.getMinutes();var curr_seg = d.getSeconds();var time = curr_hour + " : " + curr_min + " : " + curr_seg; Irokhes, this will give client side time ie of clients machine . If we need the time with respect to server you know it won't work. Yes if orignal poster has the requirement to go with the client side time then you are right .
Sir could you explain me what is meaning of this line(If we need the time with respect to server you know it won't work.) and why wont work?
Thanks in advance.