Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Checkbox and Javascript

Reply
Thread Tools

Checkbox and Javascript

 
 
tabbykitty
Guest
Posts: n/a
 
      11-30-2005
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

 
Reply With Quote
 
 
 
 
Santhi Maadhaven
Guest
Posts: n/a
 
      12-01-2005
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
>
>

 
Reply With Quote
 
 
 
 
tabbykitty
Guest
Posts: n/a
 
      12-02-2005
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
 
Reply With Quote
 
tabbykitty
Guest
Posts: n/a
 
      12-02-2005
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
 
Reply With Quote
 
tabbykitty
Guest
Posts: n/a
 
      12-02-2005
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
 
Reply With Quote
 
Santhi Maadhaven
Guest
Posts: n/a
 
      12-02-2005
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
>

 
Reply With Quote
 
tabbykitty
Guest
Posts: n/a
 
      12-02-2005


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(Str ing 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
 
Reply With Quote
 
Santhi Maadhaven
Guest
Posts: n/a
 
      12-03-2005
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(Str ing 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
>

 
Reply With Quote
 
tabbykitty
Guest
Posts: n/a
 
      12-03-2005
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
 
Reply With Quote
 
Santhi Maadhaven
Guest
Posts: n/a
 
      12-03-2005
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPNET CheckBox and a CheckBox in a TemplateField Jason Huang ASP .Net 0 06-29-2007 12:35 AM
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
disable checkbox list checkbox Vikram ASP .Net 1 01-25-2006 02:59 PM
Text on Checkbox below the checkbox tshad ASP .Net 0 04-14-2005 11:26 PM
HELP - select all checkbox javascript works fine.. unless there is only one checkbox. Michael Champagne Javascript 4 04-20-2004 01:40 AM



Advertisments