Checkbox and Javascript

Discussion in 'ASP .Net Web Controls' started by tabbykitty, Nov 30, 2005.

  1. tabbykitty

    tabbykitty Guest

    Hi there

    I have created a record update form. All of the controls are databound.
    One of the controls on the form is a checkbox and determines whether
    the record is 'Active' or not. What i want to happen is that when the
    checkbox is checked (or unchecked), that another field on my form
    (Start Date)which is also databound gets changed to todays date (with
    the date taken from the clients side), i would also like to have
    another field change to todays date + 365 days (End Date). I dont want
    to use postback. I presume that i will need some client side scripting.

    Does anyone have any idea how i can do this?

    I am a total newbie using vb but not yet using code behind

    Any help greatly appreciated
     
    tabbykitty, Nov 30, 2005
    #1
    1. Advertising

  2. Hi,
    Add onClick event of client side script in codebehind for checkbox
    control like
    chkBox.Attributes.Add("onClick","javascript:Test()"); This code will add
    client side script event to server control.

    In aspx page,add below script inside head
    <script language="javascript">
    function Test()
    {
    //This will set the value to textbox server control
    document.forms[0]['txtBox1'].value = date;
    }
    </script>

    "tabbykitty" wrote:

    > Hi there
    >
    > I have created a record update form. All of the controls are databound.
    > One of the controls on the form is a checkbox and determines whether
    > the record is 'Active' or not. What i want to happen is that when the
    > checkbox is checked (or unchecked), that another field on my form
    > (Start Date)which is also databound gets changed to todays date (with
    > the date taken from the clients side), i would also like to have
    > another field change to todays date + 365 days (End Date). I dont want
    > to use postback. I presume that i will need some client side scripting.
    >
    > Does anyone have any idea how i can do this?
    >
    > I am a total newbie using vb but not yet using code behind
    >
    > Any help greatly appreciated
    >
    >
     
    Santhi Maadhaven, Dec 1, 2005
    #2
    1. Advertising

  3. tabbykitty

    tabbykitty Guest

    Thank you very much for your reply
    Next step for me is finding a bit of javascript that will be able to do
    that.

    I will give that a go and let you know how i get on.

    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 2, 2005
    #3
  4. tabbykitty

    tabbykitty Guest

    Whoops

    Didnt see the your bit of javascipt in there, i will definitely try that
    out

    Thank you

    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 2, 2005
    #4
  5. tabbykitty

    tabbykitty Guest

    Hi Santhi

    I have given it a try but i think that i must be doing something wrong
    as nothing is happening when i click the checkbox (please bear in mind
    that i am totally new to any sort of coding so there is a high
    possibility that i have messed up somewhere)

    Here is what i put in the head of the page with the form in it (i am not
    utilising code behind as i am using dreamweaver at the moment but i will
    do all that at a later stage)

    <script language="javascript">
    function Test()
    {
    //This will set the value to textbox server control
    document.forms[form1]['StartDate'].value = date;
    }
    </script>

    <script language="VB" runat="server">
    public sub page_load(Src As Object, E As EventArgs)
    Active.Attributes.Add("onClick","javascript:Test()")

    End Sub
    </script>

    Do i need to add any code to my actual checkbox within the page?

    Thank you very much


    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 2, 2005
    #5
  6. Hi,
    Add this line of code var date = new Date(); inside the javascript
    before document.forms[form1]['StartDate'].value = date;

    "tabbykitty" wrote:

    > Hi Santhi
    >
    > I have given it a try but i think that i must be doing something wrong
    > as nothing is happening when i click the checkbox (please bear in mind
    > that i am totally new to any sort of coding so there is a high
    > possibility that i have messed up somewhere)
    >
    > Here is what i put in the head of the page with the form in it (i am not
    > utilising code behind as i am using dreamweaver at the moment but i will
    > do all that at a later stage)
    >
    > <script language="javascript">
    > function Test()
    > {
    > //This will set the value to textbox server control
    > document.forms[form1]['StartDate'].value = date;
    > }
    > </script>
    >
    > <script language="VB" runat="server">
    > public sub page_load(Src As Object, E As EventArgs)
    > Active.Attributes.Add("onClick","javascript:Test()")
    >
    > End Sub
    > </script>
    >
    > Do i need to add any code to my actual checkbox within the page?
    >
    > Thank you very much
    >
    >
    > tabbykitty
    >
    > --
    > Sent via .NET Newsgroups
    > http://www.dotnetnewsgroups.com
    >
     
    Santhi Maadhaven, Dec 2, 2005
    #6
  7. tabbykitty

    tabbykitty Guest

    Hi Santhi

    You are a star, it worked!

    One problem though. When i now try to submit the form, i get this error

    System.FormatException: String was not recognized as a valid DateTime.
    at System.DateTimeParse.Lex(Int32 dps, __DTString str, DateTimeToken
    dtok, DateTimeRawInfo raw, DateTimeResult result, DateTimeFormatInfo&
    dtfi)
    at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
    DateTimeStyles styles)
    at System.DateTime.Parse(String s, IFormatProvider provider,
    DateTimeStyles styles)
    at System.DateTime.Parse(String s, IFormatProvider provider)
    at System.DateTime.Parse(String s)
    at DreamweaverCtrls.DataSet.ConvertParameterValue(String strValue, Enum
    theType)
    at DreamweaverCtrls.DataSet.AddParameters(IDbCommand myCommand)
    at DreamweaverCtrls.DataSet.DoInit()


    I have the dates in those boxes formated this way '04 October 2006'

    I have tried taking the formatting off the control but that doesnt make
    any difference

    Dont suppose that you have any idea how i can get around this do you?

    Thank you so much for your help so far, i am very happy that it is at
    least doing as much as it is.
    If you can help me solve this completely i will be over the moon!



    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 2, 2005
    #7
  8. Hi,

    Date FormatException will occur when u the date is not valid. Can u just
    post me what u have done in code for parsing the date?

    "tabbykitty" wrote:

    >
    >
    > Hi Santhi
    >
    > You are a star, it worked!
    >
    > One problem though. When i now try to submit the form, i get this error
    >
    > System.FormatException: String was not recognized as a valid DateTime.
    > at System.DateTimeParse.Lex(Int32 dps, __DTString str, DateTimeToken
    > dtok, DateTimeRawInfo raw, DateTimeResult result, DateTimeFormatInfo&
    > dtfi)
    > at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
    > DateTimeStyles styles)
    > at System.DateTime.Parse(String s, IFormatProvider provider,
    > DateTimeStyles styles)
    > at System.DateTime.Parse(String s, IFormatProvider provider)
    > at System.DateTime.Parse(String s)
    > at DreamweaverCtrls.DataSet.ConvertParameterValue(String strValue, Enum
    > theType)
    > at DreamweaverCtrls.DataSet.AddParameters(IDbCommand myCommand)
    > at DreamweaverCtrls.DataSet.DoInit()
    >
    >
    > I have the dates in those boxes formated this way '04 October 2006'
    >
    > I have tried taking the formatting off the control but that doesnt make
    > any difference
    >
    > Dont suppose that you have any idea how i can get around this do you?
    >
    > Thank you so much for your help so far, i am very happy that it is at
    > least doing as much as it is.
    > If you can help me solve this completely i will be over the moon!
    >
    >
    >
    > tabbykitty
    >
    > --
    > Sent via .NET Newsgroups
    > http://www.dotnetnewsgroups.com
    >
     
    Santhi Maadhaven, Dec 3, 2005
    #8
  9. tabbykitty

    tabbykitty Guest

    Hi

    Here is what i have done whith the textbox in the page

    <asp:TextBox Columns="20" ID="StartDate" runat="server"
    TextMode="SingleLine" text='<%#
    DateTime.Parse(dsadvertiser.FieldValue("StartDate",
    Container)).ToString("D") %>' />

    Is this all you need?

    Thank you

    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 3, 2005
    #9
  10. Hi ,
    Check this line of code
    'dsadvertiser.FieldValue("StartDate",Container))' whether it has the proper
    date value ..I feel this is the problem..


    "tabbykitty" wrote:

    > Hi
    >
    > Here is what i have done whith the textbox in the page
    >
    > <asp:TextBox Columns="20" ID="StartDate" runat="server"
    > TextMode="SingleLine" text='<%#
    > DateTime.Parse(dsadvertiser.FieldValue("StartDate",
    > Container)).ToString("D") %>' />
    >
    > Is this all you need?
    >
    > Thank you
    >
    > tabbykitty
    >
    > --
    > Sent via .NET Newsgroups
    > http://www.dotnetnewsgroups.com
    >
     
    Santhi Maadhaven, Dec 3, 2005
    #10
  11. tabbykitty

    tabbykitty Guest

    Hi Santhi

    Dont know much about Javascript (understatement of the year) but is it
    possible that i need to use a bit of javascipt that will put the date
    into the textbox in the correct format. At the moment i get this date
    put in the textbox 'Sat Dec 03 2005 20:24:04 GMT+0200 (South Africa
    Standard Time)'

    I have tried testing out my textbox (as you suggested) and it seems that
    all is well and the form submits fine if i get rid of the end bit
    (GMT+0200 (South Africa Standard Time)), my form doesnt like that bit at
    all.

    If it is possible, have you any idea what the javascript should be? I
    have tried various bits that i found on the net and tried to modify them
    so that they would work with my form but with no luck.

    So close yet so far away, any more help with this will be greatly
    appreciated, thank you in advance

    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 3, 2005
    #11
  12. Hi,
    Got ur problem. Use the code below in javascript to format the date in
    dd/mm/yyyy format.This will solve ur problem
    var date = new Date();
    var d = date.getDate();
    var day = (d < 10) ? '0' + d : d;
    var m = date.getMonth() + 1;
    var month = (m < 10) ? '0' + m : m;
    var yy = date.getYear();
    var year = (yy < 1000) ? yy + 1900 : yy;
    date = day + "/" + month + "/" + year;

    Rgds,
    Santhi.M

    "tabbykitty" wrote:

    >
    >
    > Hi Santhi
    >
    > Dont know much about Javascript (understatement of the year) but is it
    > possible that i need to use a bit of javascipt that will put the date
    > into the textbox in the correct format. At the moment i get this date
    > put in the textbox 'Sat Dec 03 2005 20:24:04 GMT+0200 (South Africa
    > Standard Time)'
    >
    > I have tried testing out my textbox (as you suggested) and it seems that
    > all is well and the form submits fine if i get rid of the end bit
    > (GMT+0200 (South Africa Standard Time)), my form doesnt like that bit at
    > all.
    >
    > If it is possible, have you any idea what the javascript should be? I
    > have tried various bits that i found on the net and tried to modify them
    > so that they would work with my form but with no luck.
    >
    > So close yet so far away, any more help with this will be greatly
    > appreciated, thank you in advance
    >
    > tabbykitty
    >
    > --
    > Sent via .NET Newsgroups
    > http://www.dotnetnewsgroups.com
    >
     
    Santhi Maadhaven, Dec 4, 2005
    #12
  13. tabbykitty

    tabbykitty Guest

    Hi Santhi

    Worked like a charm!!

    Thank you so much for all your help and time. Really appreciated

    Thank you again.

    tabbykitty

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
     
    tabbykitty, Dec 4, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    0
    Views:
    581
    tshad
    Apr 15, 2005
  2. Vikram

    disable checkbox list checkbox

    Vikram, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,430
    ThunderMusic
    Jan 25, 2006
  3. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    865
    David Wier
    Oct 6, 2006
  4. Jason Huang
    Replies:
    0
    Views:
    585
    Jason Huang
    Jun 29, 2007
  5. Michael Champagne
    Replies:
    4
    Views:
    358
    Matt Kruse
    Apr 20, 2004
Loading...

Share This Page