By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

Merge to functions

P: n/a
How do I "merge" the two functions below - checkFromDate() and
checkToDate() - so that I only have one function. I want to do the same
validation in both text fields, but only have one function that does all
the validation.

<html>
<head>
<script language="JavaScript">
function checkFromDate() {
var ToFrom = document.form.txtFromDate.value
// Do some other validation...
}

function checkToDate() {
var ToDate = document.form.txtToDate.value
// Do same validation as above...
}
</script>
</head>
<body>
Start Date : <input type="text" name="txtFromDate"
onBlur="checkFromDate()"> yyyy/mm/dd <br>
End Date : <input type="text" name="txtToDate" onBlur="checkToDate()">
yyyy/mm/dd
</body>
</html>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
*** Andy wrote/escribió (15 Mar 2005 03:04:46 -0600):
How do I "merge" the two functions below - checkFromDate() and
checkToDate() - so that I only have one function. function checkFromDate() {
var ToFrom = document.form.txtFromDate.value
// Do some other validation...
}

function checkToDate() {
var ToDate = document.form.txtToDate.value
// Do same validation as above...
}


function checkDate() {
var ToFrom = document.form.txtFromDate.value
var ToDate = document.form.txtToDate.value
// Do some other validation...
}

--
-- Álvaro G. Vicario - Burgos, Spain
-- Don't e-mail me your questions, post them to the group
--
Jul 23 '05 #2

P: n/a
> How do I "merge" the two functions below - checkFromDate() and
checkToDate() - so that I only have one function. I want to do the same
validation in both text fields, but only have one function that does all
the validation. function checkFromDate() {
var ToFrom = document.form.txtFromDate.value
// Do some other validation...
}

function checkToDate() {
var ToDate = document.form.txtToDate.value
// Do same validation as above...
}


You can make a more generic function:

function checkDate(value) {
// Do some validation on value...
}

checkDate(document.form.txtFromDate.value);
checkDate(document.form.txtToDate.value);

That way you can reuse the function on other forms in other applications.

http://www.JSLint.com
Jul 23 '05 #3

P: n/a
Andy wrote:
[...]
function checkFromDate() {
var ToFrom = document.form.txtFromDate.value
// Do some other validation...
}


There is a good coverage of date validation here:

<URL:http://www.merlyn.demon.co.uk/js-date4.htm>
--
Rob
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.