Author Topic: glitch in Javascript  (Read 453 times)

Offline pavansss91

  • Level 18
  • *
  • Posts: 185
  • Reputation: +1/-0
    • View Profile
glitch in Javascript
« on: July 07, 2009, 08:50:12 AM »
Code: [Select]
var od="";
var odc="";

function cal_ajax_date(d,m,y)
{
 if(d=="-")
  return false;
 else
 {
  var dt=y+"-"+m+"-"+d;
  calendardateajax(dt);
  if(od!="")
   document.getElementById(od).className=odc;
  odc=document.getElementById(dt).className;
  document.getElementById(dt).className="cal_select";
  od=dt;
  return true;
 }
}

What is the difference between first and below

Code: [Select]
var od="";
var odc="";

function cal_ajax_date(d,m,y)
{
 if(d=="-")
  return false;
 else
 {
  var dt=y+"-"+m+"-"+d;
  calendardateajax(dt);  //this is another function which displays a data using ajax.php
  if(od!="")
   document.getElementById(od).className=odc;
  alert(dt);
  odc=document.getElementById(dt).className;
  document.getElementById(dt).className="cal_select";
  od=dt;
  return true;
 }
}

Don't say alertbox. I am asking what is the other difference because when i have

Code: [Select]
<?php
$d
=date("j",time());
$m=date("n",time());
$y=date("Y",time());

echo 
"
<script type=text/javascript>
window.onload=cal_ajax_date(
$d,$m,$y)
</script>"
;

?>


this in the main script i get

1st code: Error
                document.getElementById(dt) is null
                cal_ajax_date(1, 7, 2009)
                (?)()
                odc=document.getElementById(dt).className;


2nd code: It works fine as i wanted (actually i don't want the alertbox)

I don't understand where the mistake is
Somebody Help me Please
« Last Edit: July 07, 2009, 08:51:52 AM by pavansss91 »
bbgFramework v0.1.3
Sun Database Class v0.3

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: glitch in Javascript
« Reply #1 on: July 07, 2009, 10:24:06 AM »
I'm not really sure, but judging from what you wrote about it - can't it be that the part after alert doesn't have to be availible immediately for the script and the alert creates a timeframe in which it can be made availible and allow the script to work properly?
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal