tags:

views:

232

answers:

6
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8">
<title>YUI Calendar Control Example</title>
<link rel="stylesheet"
type="text/css"
href="yui/build/calendar/assets/skins/sam/calendar.css">
<script type="text/javascript"
src="yui/build/yahoo-dom-event/
yahoo-dom-event.js"></script>
<script type="text/javascript"
src="yui/build/calendar/calendar-min.js"></script>
<style type="text/css">
input {
margin:0px 10px 0px 10px;
}
</style>
</head>
<body class="yui-skin-sam">
<div>
<label>Please enter your date of birth:</label>
<input type="text" name="dobfield" id="dobfield">
<img id="calico" src="E:\HP_PROJECT\cal.png"
alt="Open the Calendar control">
</div>
<div id="mycal"></div>
<script type="text/javascript">
//create the namespace object for this example
YAHOO.namespace("yuibook.calendar");
//define the lauchCal function which creates the calendar
YAHOO.yuibook.calendar.launchCal = function() {
//create the calendar object, specifying the container
Var myCal = new YAHOO.widget.Calendar("mycal");
//draw the calendar on screen
myCal.render();


}
//define the showCal function which shows the calendar
Var showCal = function() {
//show the calendar
myCal.show();
}

//create calendar on page load
YAHOO.util.Event.onDOMReady(YAHOO.yuibook.calendar.launchCal);
 //attach listener for click event on calendar icon
YAHOO.util.Event.addListener("calico", "click", showCal);  
//myCal.hide();



</script>

</body>
</html>

I have used the above code. But the problem with the code is that when I click image icon nothing is displayed. I am new to javascript. Please help me how to implement listener.

Please guide me where to do chages in the code.

Thanks Padmaja

+1  A: 

The problem is that myCal is a local variable to the launchCal() function. Giving the myCal variable a globally-accessible namespace will make it available to every scope.

Here's your original code (someone else accidentally put my correct code in your original question =/)

YAHOO.namespace("yuibook.calendar"); 

//define the lauchCal function which creates the calendar 
YAHOO.yuibook.calendar.launchCal = function() { 

    //create the calendar object, specifying the container 
    var myCal = new YAHOO.widget.Calendar("mycal"); 

    //draw the calendar on screen 
    myCal.render(); 
}

//define the showCal function which shows the calendar
Var showCal = function() { 
    //show the calendar 
    myCal.show(); 
} 

//create calendar on page load
YAHOO.util.Event.onDOMReady(YAHOO.yuibook.calendar.launchCal); 

//attach listener for click event on calendar icon 
YAHOO.util.Event.addListener("calico", "click", showCal); 

//myCal.hide();

Now see my changes. Note the use of the global YAHOO namespace.

YAHOO.namespace("yuibook.calendar"); 

//define the lauchCal function which creates the calendar 
YAHOO.yuibook.calendar.launchCal = function() { 

    //create the calendar object, specifying the container 
    YAHOO.yuibook.calendar.myCal = new YAHOO.widget.Calendar("mycal"); 

    //draw the calendar on screen 
    myCal.render(); 
}

//define the showCal function which shows the calendar
Var showCal = function() { 
    //show the calendar 
    YAHOO.yuibook.calendar.myCal.show(); 
} 

//create calendar on page load
YAHOO.util.Event.onDOMReady(YAHOO.yuibook.calendar.launchCal); 

//attach listener for click event on calendar icon 
YAHOO.util.Event.addListener("calico", "click", showCal); 

//myCal.hide();
Triptych
Your answer should be in your answer, not his question. Now I have no idea what he was asking because you've changed the question to an "answer". What did he do wrong in the original question? How can someone learn from his mistake?
jmucchiello
I didn't do that, le dorfier did. Hopefully he changes it back. I don't have enough authority or whatever to edit other people's posts. Anyway - I rolled mine back to show my answer.
Triptych
this answer identifies the problem but the code has a couple issues. the statement `myCal.render();` needs to be updated to `YAHOO.yuibook.calendar.myCal.render();`. also `Var showCal ... ` needs to be made `var showCal ... ` since js is case-sensitive and the correct keyword is `var` with a little v. this mistake is repeated in the source material (see comment on OP) several times. and not an issue with your answer but there is nothing in the original code to hide the calendar before the `image is clicked, so it's always visible.
lincolnk
A: 

Hi Triptych,

I doint understand where u have made chages . Can you please mention in the code the changes you have made. Iam unabke to identify the changes you have made

Just edited my post to make that clear. We were struck by an errant editor.
Triptych
A: 
YAHOO.namespace("yuibook.calendar"); 

//define the lauchCal function which creates the calendar 
YAHOO.yuibook.calendar.launchCal = function() { 

    //create the calendar object, specifying the container 
    YAHOO.yuibook.calendar.myCal = new YAHOO.widget.Calendar("mycal"); 

    //draw the calendar on screen 
    myCal.render(); 
}

//define the showCal function which shows the calendar
Var showCal = function() { 
    //show the calendar 
    YAHOO.yuibook.calendar.myCal.show(); 
} 

//create calendar on page load
YAHOO.util.Event.onDOMReady(YAHOO.yuibook.calendar.launchCal); 

//attach listener for click event on calendar icon 
YAHOO.util.Event.addListener("calico", "click", showCal); 

//myCal.hide();

I have tried with the above code. But unable to see the calendar when I click the image. Can anybody help me?

Thanks in advance.

hey. you should delete your two responses, and then copy your code from MY answer, and put it in your original post. Also, do try my solution (the second block of code in my answer)
Triptych
A: 

Hi Triptych,

I dont see any changes between your code and my code. Any how my problem is not solved. Can u please send the complete script as i am new to understand javascript.

Thanks in advance

A: 

the code doesn't work...can anyone explain what css is exactly doing here???

Sandesh
A: 

the calendar is not displayed no matter how many changes i make in the code...I tried Triptychs's changes too but with no success...it just doesn't display itself...plz help

Sandesh