|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Checkbox and JavascriptHi 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 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> Show quoteHide quote "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 > > 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 Whoops
Didnt see the your bit of javascipt in there, i will definitely try that out Thank you tabbykitty 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 Hi,
Add this line of code var date = new Date(); inside the javascript before document.forms[form1]['StartDate'].value = date; Show quoteHide quote "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 > 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 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? Show quoteHide quote "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 > 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 Hi ,
Check this line of code 'dsadvertiser.FieldValue("StartDate",Container))' whether it has the proper date value ..I feel this is the problem.. Show quoteHide quote "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 > 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 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 Show quoteHide quote "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 > Hi Santhi
Worked like a charm!! Thank you so much for all your help and time. Really appreciated Thank you again. tabbykitty
VS2005 DataList with Nested GridView using ObjectDataSource
Validators in composite control firing prematurely BoundField and DataFormatString in ASP.NET 2.0 - Bug ? Problem with Custom Web Controls in Visual Studio 2005 GridView whole row select Custom control that ingerits from textbox datagrid pixel height not respected ReadOnly (HTML) controls to stay black and not grey How to cycle through checkboxes in a datagrid and find out which ones are checked? Dynamic user control Event Handling (VS.NET Ent 2003) |
|||||||||||||||||||||||