Reduceing Javascript Lag

This is a discussion on "Reduceing Javascript Lag" within the JavaScript Forum section. This forum, and the thread "Reduceing Javascript Lag are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 17th, 2007, 20:57
New Member
Join Date: Aug 2007
Location: Your C:\WINDOWS
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Reduceing Javascript Lag

I have this contact form (cathering.co.uk/contact.php)

In FireFox And IE6 Is creates huge lag when you fill in the last field that it validates I think it dose it because in order to check if the form has been correctly filled out I have a put a SetTimeOut() to the funt that disables and undisables the Send button according to if its been filled in correctly but once its called it goes into a loop by using SetTimeOut(); I narrowed it down to that being the source of the lagginess i tried slowing it down from 1 millisecond to 50 milliseconds it didet really help alot I know its the javascript because i removed the JS file and it worked with out any lag, but even after doing that it still had mass lag ( The Program Just became inrespondive) Any ideas to stop the lag?

Also if i slow it down to more than 500 milliseconds it can be open to people clicking the submit button in time .

Heres javascript code:
HTML: Select all
var re = new RegExp("[a-zA-Z]");
var disable1 = 0;
var disable2 = 0;
var disable3 = 0;
var disable4 = 0;
var disable5 = 1;
var disable6 = 0;

function validate(type,input,errordisplay){
if(type == "blank1"){
if(!input.value.match(re)){
errordisplay.innerHTML = '<span style="color:#FF0000;">Invalid Input</span>';
disable1 = 0;
}
else {
disable1 = 1;
errordisplay.innerHTML = '<span style="color:#006600;">Valid Input</span>'}}

if(type == "blank2"){
if(!input.value.match(re)){
errordisplay.innerHTML = '<span style="color:#FF0000;">Invalid Input</span>';
disable2 = 0;
}
else {
disable2 = 1;
errordisplay.innerHTML = '<span style="color:#006600;">Valid Input</span>'}}

if(type == "blank3"){
if(!input.value.match(re)){
errordisplay.innerHTML = '<span style="color:#FF0000;">Invalid Input</span>';
disable3 = 0;
}
else {
disable3 = 1;
errordisplay.innerHTML = '<span style="color:#006600;">Valid Input</span>'}}



if (type == "email"){
check=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
if(! check.test(input.value)){
errordisplay.innerHTML = '<span style="color:#FF0000;">Invalid Input</span>';
disable4 = 0;
}
else {
disable4 = 1;
errordisplay.innerHTML = '<span style="color:#006600;">Valid Input</span>'}}

if(type == "confirmemail"){
if(input.value.toLowerCase() != document.getElementById("contact_form").email.value.toLowerCase())
{errordisplay.innerHTML = '<span style="color:#FF0000;">Invalid Input</span>'
disable6 = 0;}
else {
disable6 = 1;
errordisplay.innerHTML = '<span style="color:#006600;">Valid Input</span>'}}}

function checksubmitbutton(){
if(disable1 == 1 && disable2 == 1 && disable3 == 1 && disable4 == 1 && disable5 == 1 && disable6 == 1){
document.getElementById('contact_form').submit.disabled=false;
setTimeout('checksubmitbutton()',500);}
else {
document.getElementById('contact_form').submit.disabled=true;}
setTimeout('checksubmitbutton()',500);
}

Last edited by cathering1; Aug 17th, 2007 at 21:01.
Reply With Quote

  #2 (permalink)  
Old Aug 20th, 2007, 15:06
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 147
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to ScottR Send a message via Skype™ to ScottR
Re: Reduceing Javascript Lag

That's not alot of code. So it shouldn't create a lag. The only thing that I see that may have been done differently is to have your submit button disabled, at the end of your function set it to enabled. If it doesn't reach the end of the function, it doesn't get enabled.
Reply With Quote
Reply

Tags
javascript

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
php and javascript yvettesio JavaScript Forum 8 Mar 14th, 2007 23:18
Javascript Help Daniel JavaScript Forum 5 Jan 4th, 2007 22:00
JavaScript cbrams9 JavaScript Forum 1 Sep 20th, 2006 17:35
Can someone help me with this javascript Galaxyblue JavaScript Forum 2 Mar 11th, 2004 12:18
what does \\ mean in javascript jenjen1018 JavaScript Forum 5 Jan 6th, 2004 17:05


All times are GMT. The time now is 05:39.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43