Problem with javascript

hi all,
i have created one program using javascript.i have written using javascript functions…
can u tell me what is the problem with my program i have saved it as messages.js,but the script is not executing can u tell me what went wrong…
below is my javascript program…


// form validation function //
 function checkName(form)
{
  var eobj=document.getElementById('realnameerror');
  var sRealName = form.realname.value;
  var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;
  var error=false;
  eobj.innerHTML='';
  if (sRealName == '') 
  {
   error='Error: Username cannot be blank!';
  }
  else if (sRealName.length < 4) 
  {
    error="UserName should be atleast 4 characters long";
  }
  else if (!oRE.test(sRealName))
  {
   error="Incorrect format.";
  }
  if (error)
{
   if (hasFocus == false) 
   {
     form.realname.focus();
     hasFocus = true;
   } 
   eobj.innerHTML=error;
   return false;
  }
  return true;
 }

function checkEmail(form)          /* for email validation */
{
 var eobj=document.getElementById('emailerror');
 eobj.innerHTML='';
 var error = false;
  if (form.email.value.length == 0) 
  {
    error = 'Please enter email.';
  } else if (/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$/.test(form.email.value))
 {
  return true;
 } else 
 {
   error = 'Invalid E-mail Address! Please re-enter.';
 }
 if (error) 
{
   eobj.innerHTML=error;
   if (!hasFocus) 
   {
     form.email.focus();
     hasFocus = true;
   } 
   return false;
 }

 return true;
}

function validatePwd(form)          /* password & retype-password verification */
{       
 var eobj1=document.getElementById('passworderror');
 var eobj2=document.getElementById('password2error');
 var minLength=6;
 var invalid=' ';
 var pw1=form.password.value;
 var pw2=form.password2.value;
 var error=false;
 eobj1.innerHTML='';
 eobj2.innerHTML='';
 if (pw1.length<1)
 {
  error='Please enter your password.';
 }
 else if (pw1.length < minLength)
 {
  error='Your password must be at least ' + minLength + ' characters long. Try again.';
 }
 else if (pw1.indexOf(invalid) > -1)
 {
  error='Sorry, spaces are not allowed.';
 } 
else if (pw2.length == 0) 
{
  error='Please retype password.';
   if (!hasFocus) 
   {
     form.password2.focus();
     hasFocus = true;
   } 
  eobj2.innerHTML=error;
  return false;
 }
 if (error)
 {
   if (!hasFocus) 
   {
     form.password.focus();
     hasFocus = true;
   } 
    eobj1.innerHTML=error;
  return false;
 }
 if (pw1 != pw2)
 {
  eobj2.innerHTML=' passwords not matching.Please re-enter your password.';
   if (!hasFocus) 
   {
     form.password2.focus();
     hasFocus = true;
   } 
  return false;
 }
 return true;
}

function validPhone(form)              /* phone no validation */
{          
 var eobj=document.getElementById('phonenoerror');
 var valid = '0123456789';
 var phone = form.phoneno.value;
 var error=false;
 var i=0;
 var temp;
 eobj.innerHTML='';
 if (phone == '')
 {
  error='This field is required. Please enter phone number';
 }
 else if (!phone.length > 1 || phone.length < 10)
 {
  error='Invalid phone number length! Please try again.';
 }
 else 
 {
  for (i=0; i < phone.length; i++)
 {
   temp = '' + phone.substring(i, i + 1);
   if (valid.indexOf(temp) == -1)
    {
    error='Invalid characters in your phone. Please try again.';
    }
  }
 }
 if (error)
 {
   if (!hasFocus) 
   {
     form.phoneno.focus();
     hasFocus = true;
   } 
  eobj.innerHTML=error;
  return false;
 }
 return true;
}

function validate() 
 {
  hasFocus = false;
 var form = document.forms['form'];
 var ary=[checkName,checkEmail,validatePwd,validPhone];
 var rtn=true;
 var z0=0;
 for (var z0=0;z0<ary.length;z0++)
{
  if (!ary[z0](form))
  {
    rtn=false;
  }
 }
 return rtn;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}
// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}

means in my “shoppingcart.php” i have function as

function del(pid)
{
if(confirm(‘Do you really mean to delete this item’))
{
document.form1.pid.value=pid;
document.form1.command.value=‘delete’;
document.form1.submit();
}
}
which can be written in jquery as
$(‘.pid’).remove();

is that so.
what do u mean by plugins in jquery

That’s all included as a part of the smart cart package.
Smart Cart - flexible and feature rich jQuery plug-in for shopping cart - Tech Laboratory

hi,
in the smart cart plugin in Smart Cart - jQuery shopping cart plugin
http://http://plugins.jquery.com/plugin-tags/shopping-cart
version 0.95 beta i want products on one page and no of items selected on other page.
please kindly tell me how to do that…


hi,
in the smart cart plugin in Smart Cart - jQuery shopping cart plugin
http://http://plugins.jquery.com/plu…/shopping-cart
version 0.95 beta i want products on one page and no of items selected on other page.
please kindly tell me how to do that…

but atleast the basics of jquery.the script i have posted using php can also be done using AJAX and CSS right…

I’m not sure. I don’t have the time to investigate such things right now.

atleast what i have done is correct or not.
is that code can be done in much shorter way…

The whole point of jquery and their plugins is so that the code does not need to be understood by people, only the interface.

that is right.what u are telling is an advance stage.i need to first under stand the jquery first.
can it be done using ajax also…
have u seen the thread i have posted the shoping cart example in php…

i have checked the shopping cart plug in u given me.it is simple.i have 2 js files namely jquery-1.3.2.min and jquery.smartcart-2.0 so we need not worry
how these code is written as they are ready made…
is that so…
so we need to worry about only php ansd css right…

If you are going to use one of the shopping cart plugins, you will find it best to redesign according to the typically best-practice techniques that they use there.

since i am an beginner i cant understand the code they have written.
i am using mysql database and i am storing the serial no of the item,name of the item,price of an item,description,and image of the item…
have u checked the code i have posted it is in php and javascript…
that is the simple one.
i too need like that one using jquery…

There’s a plugin tag for that: Shopping Cart | jQuery Plugins

but surely i am no where to use jquery plugins since i am an beginner.tell me whether which one is easy to use either php with javascript or php with jquery.
because i was given a task of shopping cart example like adding items and deleting items…
as i have posted the thread…

tell me where can i find a simle shopping cart examples…

No, that’s not so. The remove() method just removes the HTML element (and all its children) from the page.

jQuery’s primary purpose is to make it easier to manipulate the DOM.

Other people also create plugins that make it easier for you to manipulate other things too.

can u tell me in brief how the structure should look like.
whether instead of just using functions i need to replace with jquery or even the php code also should be replaced…
give me brief idea.i am new to jquery…

What you can do is to look through the jQuery documentation, and use its methods to replace as much of the JavaScript code as you can.

Give it a try, and see what you come up with.

Structure can be worked on once you have some jQuery code to work with. You may find that jQuery doesn’t provide enough of a benefit in your particular situation, or that plugins such as the jQuery validator can be put to use to reduce most of your code.

The problem is, that jQuery is just a bunch of JavaScript functions, so it adds a large overhead on top of things, if you’re worried about the amount of code being used.

whether is it possible to use jquery instead of javascript in the thread i have posted.it is working nice with javascript.
but i want to reduce the no of lines so i want tu use jquery…
how can i do it…