Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help calling Client JavaScript

Status
Not open for further replies.

kss444

Programmer
Sep 19, 2006
306
US
I have a client side java script funtion that I am creating from the code behind page using RegisterStartupScript.
I also have a control on my page, that has a SelectedDate property that gives me the date the user selected.
What I am wanting to do is some more validation, so I want to call my JS passing in the control.

How can I do this?

function ValidateForm(strDate) {
var dt = strDate;
//var dt=document.frmSample.txtDate
if(!isDate(dt.SelectedDate)){
//if (isDate(dt.value)==false){
dt.focus()
return false
}
return true
}
Thanks,
KSS

Ordinary Programmer
 
I have a client side java script funtion that I am creating from the code behind page using RegisterStartupScript.
Why? wouldn't it be better to keep the js on the client and .net on the server.

research the CustomValidator webcontrol. you can assign a javascript function to the client validation member this way the validation, error message, etc can work the same way a RequiredField or Range validator works.

Note: never trust client validation, always validate data on the server as well. using the CustomValidator, assign a handler to the ServerValidate (or something like that) event.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Well the main reason is that it is a 3rd party date control that does validation just fine, but now I have to change the one of the properties on the control to allow the user to type in a date.
(it's a control that you select an icon the select a date and the date is populated in a textbox)

And when you make the control editable like this it does not seem to validate for leap year ect..
So I found a date script that works great, but I can't add a onblur to the control else it would work.

So in the section of code that checks the rest of the page I was wanting to call this JS script adn pass in the date controls selected date.

Ordinary Programmer
 
in that case I would work with the 3rd party vendor on this problem. they should be able to provide an optimum solution for this situation.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top