...

View Full Version : New Job, code not working Please help



sindhu
06-24-2008, 09:57 PM
I have a form where i have to put checks using javascript.The code is not working at all . I have tried many ways.I think something basic is missing.Please can someone help?




<HTML>
<HEAD>
<script>
function submitsearch()
{
document.searchform.submit();
}
</script>

<script type="javascript">
function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Please Enter Valid Email Address")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Please Enter Valid Email Address")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Please Enter Valid Email Address")
return false
}

if (str.indexOf(at,(lat+1))!=-1){
alert("Please Enter Valid Email Address")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Please Enter Valid Email Address")
return false
}

if (str.indexOf(dot,(lat+2))==-1){
alert("Please Enter Valid Email Address")
return false
}

if (str.indexOf(" ")!=-1){
alert("Please Enter Valid Email Address")
return false
}

return true
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{ var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function blankarea()
{
document.form1.description.value="";
}
function validate()
{
if(document.form1.Customer.value=="")
{
alert("Please enter Customer Name");
document.form1.Customer.value="";
document.form1.Customer.focus();
return false;
}
if(document.form1.Contact.value=="")
{
alert("Please enter Contact Name");
document.form1.Contact.value="";
document.form1.Contact.focus();
return false;
}
if(document.form1.Details.value=="")
{
alert("Enter Details of the systems whose quote required");
document.form1.Details.value="";
document.form1.Details.focus();
return false;
}
else if(document.form1.Email.value=="")
{
alert("Please enter your Email Address");
return false;
}
else if (echeck(document.form1.Email.value)==false)
{
document.form1.Email.value="";
document.form1.Email.focus();
return false;
}
else if(document.form1.Phone.value=="")
{
alert("Please enter your Phone Number");
return false;
}
else if (checkInternationalPhone(document.form1.Phone.value)==false)
{
alert("Please Enter a Valid Phone Number");
document.form1.Phone.value="";
document.form1.Phone.focus();
return false;
}
else if(document.form1.Fax.value=="")
{
alert("Please enter your Fax Number");
return false;
}
else if (checkInternationalPhone(document.form1.Fax.value)==false)
{
alert("Please Enter a Valid Fax Number");
document.form1.Fax.value="";
document.form1.Fax.focus();
return false;
}
else
{
return true;
}
}
</script>
</HEAD>



<BODY BGCOLOR=#FFFFFF leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">


<tr>
<td align="left" valign="top" class="style7">&nbsp;</td>
<td align="left" valign="top" class="style6">&nbsp;</td>
</tr>
<tr>
<td width="279" align="left" valign="top" class="style7"><span class="style13"><span class="style10"> Request Date :</span></span><span class="style6"><br>
<input name="datefield" type="text" class="style14" size="10">
<br>
</span></td>
<td width="288" align="left" valign="top" class="style6"><span class="style14">Email:</span><br>
<input name="Email" type="text" id="Email" class="style14"></td>
</tr>
<tr>
<td align="left" valign="top" class="style7"><span class="style6"><span class="style10"> Customer Name :</span><br>
<input name="customer" type="text" class="style14" id='customer'>
</span></td>
<td align="left" valign="top" class="style6"><span class="style10">Contact Person :</span><br>
<input type="contact_name" name="contact" id="contact_name" class="style14"></td>
</tr>
<tr align="left" valign="top">
<td class="style8"><span class="style10">Phone Number: </span><br>
<input name="phone" type="text" id="Phone" class="style14" size="12" maxlength="12"></td>
<td class="style7"><span class="style10">Fax Number: </span><span class="style8"><br>
<input name="fax" type="text" id="Fax" class="style14" size="12" maxlength="12">
</span></td>
</tr>
<tr align="left" valign="top">
<td class="style10">Address:<br>
<span class="style8">
<input name="address" type="text" id="address" class="style14">
</span></td>
<td class="style10">City:<br>
<span class="style8">
<input name="textfield" type="text" class="style14">
</span></td>
</tr>
<tr align="left" valign="top">
<td class="style8"><span class="style10">State:<br>
</span>
<select name="state" size="1" class="style14">
<option value=AL>Alabama</option>
<option value=AK>Alaska</option>
<option value=AZ selected>Arizona</option>
<option value=AR>Arkansas</option>
<option value=CA>California</option>
<option value=CO>Colorado</option>
<option value=CT>Connecticut</option>
<option value=DE>Delaware</option>
<option value=DC>District of Columbia</option>
<option value=FL>Florida</option>
<option value=GA>Georgia</option>
<option value=HI>Hawaii</option>
<option value=ID>Idaho</option>
<option value=IL>Illinois</option>
<option value=IN>Indiana</option>
<option value=IA>Iowa</option>
<option value=KS>Kansas</option>
<option value=KY>Kentucky</option>
<option value=LA>Louisiana</option>
<option value=ME>Maine</option>
<option value=MD>Maryland</option>
<option value=MA>Massachusetts</option>
<option value=MI>Michigan</option>
<option value=MN>Minnesota</option>
<option value=MS>Mississippi</option>
<option value=MO>Missouri</option>
<option value=MT>Montana</option>
<option value=NE>Nebraska</option>
<option value=NV>Nevada</option>
<option value=NH>New Hampshire</option>
<option value=NJ>New Jersey</option>
<option value=NM>New Mexico</option>
<option value=NY>New York</option>
<option value=NC>North Carolina</option>
<option value=ND>North Dakota</option>
<option value=OH>Ohio</option>
<option value=OK>Oklahoma</option>
<option value=OR>Oregon</option>
<option value=PA>Pennsylvania</option>
<option value=RI>Rhode Island</option>
<option value=SC>South Carolina</option>
<option value=SD>South Dakota</option>
<option value=TN>Tennessee</option>
<option value=TX>Texas</option>
<option value=UT>Utah</option>
<option value=VT>Vermont</option>
<option value=VA>Virginia</option>
<option value=WA>Washington</option>
<option value=WV>West Virginia</option>
<option value=WI>Wisconsin</option>
<option value=WY>Wyoming</option>
</select></td>
<td class="style10">Zip Code:<br>
<input name="zip" type="text" id="zip" class="style14" size="5" maxlength="5"></td>
</tr>
<tr align="left" valign="top">
<td colspan="2" class="style8"><input type="submit" value="Submit Request" name="submitvalues" style="color: #003333; font-family: MS Sans Serif; font-size: 8pt; border: 1 solid #003333"></td>
</tr>
</table>
</form>
<div align="left" class="style7"></div></td>
</tr>
</table>
</center>
</div>
</td>
</tr>
<tr>
<td width="100&#37;" height="20">
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td width="141" bgcolor="#5F6F7F" valign="top">&nbsp;

</td>
<td valign="bottom" align="left" width="609">
<img src="includes/images/cornerbottom.gif" width="16" height="16" align="absbottom">
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="19" bgcolor="5F6F7F">
<div align="right" class="bodyplainwhite"><font face="Arial, Helvetica, sans-serif" size="1"><b>&copy;
Copyright 2003. All rights reserved.
Contact: </b><font color="white"><b>A3Net Servers, Inc.</b></font></font></div>
</td>
<td height="19" width="31"><img src="includes/images/footer.gif" width="31" height="19"></td>
<td bgcolor="B4C64E" width="100">&nbsp;</td>
</tr>
</table>

</td>
</tr>
</table>
</div>
</BODY>
</HTML>

sindhu
06-24-2008, 11:26 PM
The question that I have posted before is solved.

I want to display systems date in a textfeild.Can some one help please?

rangana
06-25-2008, 02:24 AM
Date object (http://www.w3schools.com/JS/js_obj_date.asp).

sindhu
06-25-2008, 06:04 PM
How to put date object in form's text box

rangana
06-26-2008, 01:09 AM
window.onload=function()
{
var t=new Date(),
dateinp=document.getElementsByName('datefield')[0];
dateinp.style.width='450px'; // This is just to adjust the textbox's size to show the whole date
dateinp.value=t;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum