This week's book giveaway is in the Functional programming forum.
We're giving away four copies of A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles and have Ben Weidig on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

can form names b passed as parameters to javascript

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys
new to scripting. Hope u can help mi on this.
v hav a form for an inhouse reporting application.
This form takes around 100 parameters. We have to validate certain fields for checking dates, numeric values & null values.
In this scenario for field level validation wat i wil hav 2 do is 2 call this function on blur of every field & always keep on changing my java script file with different field names for all fields. Tat wuld b 2 much of coding.
Is ther a way in javascript wher v can pass the name of the field in my form to javascript function as a parameter so tat i can cari out the validation
I hav a lot of forms wher i hav 2 do the same validation.
Thanx
Sushant
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, lets see if I can help...
u = you
mi = me
v = we
hav = have
& = and
wat = what
wil = will
2 = to
tat = that
wuld = would
b = be
cari = carry
wher = where
I could have answered the question, but it took all my time to decode the rubbish above.
Please work towards reducing confusion, not extending it. The combination of different languages, grammar problems and accidental typos cause enough communication problems at the Ranch. Deliberate mush like that is just too much for me.
sorry,
Dave
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
onblur="TheFunction(this)"
onblur="TheFunction(this.value)"
onblur="TheFunction(this.text)"
onblur="TheFunction(this.checked)"
 
sushant prabhu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David
A thousand apologies .
If you can see a solution to my problem do reply.
Bye
 
sushant prabhu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric
Thanks for the solution . It works fine.
But now i am facing another problem say in a field i have 2 validations to check
say 1 is a date check & another is a null value check & the user proceeds to the next field without entering in the first field then i keep getting alert boxes saying date error & null value error & i just cant do anything not even close the browser window. the only option left is to press ctrl + alt + del .
How do i overcome this drawback.
i am pasting my code here :
<html>
<head>
<script language="javascript">

function checknull(zulu)
{
if (zulu.value== "")//** Replace 'txt1' by the name of your TextBox
{
alert("This Field Cannot Be Null !!! ");
zulu.focus();
zulu.value= "";
}
}

// ********************************************************************************



function checknumber(zulu)
{
if (zulu.value != "")//** Replace 'txt2' by the name of your TextBox
{
if (isNaN(zulu.value)== true)
{
alert("Invalid Number !!!");
zulu.focus();
zulu.value="";
}
}
}

// ********************************************************************************


function checkdate(zulu)
{
var str;
var day, month, year, s1, s2;
var mod;
str= zulu.value;
day= str.substr(0,2);
month= str.substr(3,3);
year= str.substr(7,4);
s1= str.substr(2,1);
s2= str.substr(6,1);
mod= (year % 4);
//alert(s2);

if (zulu.value== "")//** Replace 'txt3' by the name of your TextBox
{
alert("Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if (isNaN(day)== true)
{
alert("Invalid Day1 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (day.length) != 2 )
{
alert("Invalid Day2 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( ((day.length) == 2) && (day < 0 || day > 31) )
{
alert("Invalid Day3 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if (s1 != "-")
{
alert("Invalid Seperator1 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if (isNaN(month) == false)
{
alert("Invalid Month1 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(month) == true) && (month.length != 3) )
{
alert("Invalid Month2 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(month) == true) && (month.length == 3) && ((month != 'jan') && (month != 'feb') && (month != 'mar') && (month != 'apr') && (month != 'may') && (month != 'jun') && (month != 'jul') && (month != 'aug') && (month != 'sep') && (month != 'oct') && (month != 'nov') && (month != 'dec') && (month != 'JAN') && (month != 'FEB') && (month != 'MAR') && (month != 'APR') && (month != 'MAY') && (month != 'JUN') && (month != 'JUL') && (month != 'AUG') && (month != 'SEP') && (month != 'OCT') && (month != 'NOV') && (month != 'DEC') && (month !='Jan') && (month != 'Feb') && (month != 'Mar') && (month != 'Apr') && (month != 'May') && (month != 'Jun') && (month != 'Jul') && (month != 'Aug') && (month != 'Sep') && (month != 'Oct') && (month != 'Nov') && (month != 'Dec')) )
{
//alert(month.length);
alert("Invalid Month3 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (day > 30) && ( (month= "apr") || (month= "APR") || (month= "Apr") || (month= "jun") || (month= "JUN") || (month= "Jun") || (month= "sep") || (month= "SEP") || (month= "Sep") ||(month= "nov") || (month= "NOV") || (month= "Nov")) )
{
alert("Invalid Date /n Day Cannot be Greater than 30 for the Month of " + month + " !!! /n Enter Date as DD-MMM-YYYY ");
}
else if (s2 != "-")
{
alert("Invalid Seperator2 !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( isNaN(year) == true )
{
alert("Invalid Year !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( isNaN(year)== false && (year.length != 4 ) )
{
alert("Invalid Year !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(year)== false) && (year.length = 4 ) && ((year % 4)== 0) && ((month= "feb") || (month= "FEB")) && (day > 28) )
{
alert("Invalid Date /n Day Cannot be Greater than 28 for the Month of " + month + " in Leap Year !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
else if ( (isNaN(year)== false) && (year.length = 4 ) && ((year % 4) != 0) && ((month= "feb") || (month= "FEB")) && (day > 29) )
{
alert("Invalid Date /n Day Cannot be Greater than 29 for the Month of " + month + " !!! /n Enter Date as DD-MMM-YYYY ");
zulu.focus();
}
}

// ********************************************************************************
</script>
</head>
<body>
<form name="f1">
<table align="center" border="1" width="100%" cellspacing="1" cellpadding="1" bordercolor="black">
<tr>
<td>Null Validation:</td>
<td><input type="text" name="txt1" onblur="javascript:checknull(this);checknumber(this);" title="Null Not Allowed Here"></td>
</tr>

<tr>
<td>Number Validation:</td>
<td><input type="text" name="txt2" onblur="javascript:checknumber(this);" title="Only Numbers Allowed Here"></td>
</tr>

<tr>
<td>Date Validation:</td>
<td><input type="text" name="txt3" maxlength="11" onblur="javascript:checknull(this);checkdate(this);" title="Enter Date as: DD-MMM-YYYY"></td>
</tr>

</table>
</form>
</body>
</html>
 
reply
    Bookmark Topic Watch Topic
  • New Topic