Loading ...

Dropdownlist selected index change on Client side

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  client side web development   » Dropdownlist selected index change on Client side

Dropdownlist selected index change on Client side

Posts under the topic: Dropdownlist selected index change on Client side

Posted: 4/6/2010

Contributor 2237  points  Contributor
  • Joined on: 9/24/2009
  • Posts: 172

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

Starter 710  points  Starter
  • Joined on: 11/11/2009
  • Posts: 34
  Answered

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

Contributor 2237  points  Contributor
  • Joined on: 9/24/2009
  • Posts: 172

thanks irokhe.


Posted: 4/17/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483

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

Contributor 2237  points  Contributor
  • Joined on: 9/24/2009
  • Posts: 172

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.


Page 1 of 1 (5 items)