-
Problem in javascript
alright, its my first post here, i was told to come here for the help i need. alright... now ill post the html file, and the subsequent javascript file. when i change the value of my select it is supposed to call constructor function.
when it does... it says that the constructor function doesnt exist... yet, it does.
i think i am just havin a brain fart, but i really cant figure this out.
thanks in advance for any and all help.
javascript -- constructor.js
Code:
function constructor(x){
alert("I am in the constructor function");
//calls set cookie function
setMyCookie(x);
//raise the count, then drop it into a variable for easy use
raiseCount();
var currentBox = GetCookie('count');
//checks which cookies are set... fills category var appropriately
if(!GetCookie('abs_brewery') == null){
if(!GetCookie('abs_price') == null){
if(!GetCookie('abs_brand') == null){
}
else{
var category = GetCookie('abs_brewery') + GetCookie('abs_price');
}
}
else {
var category = 'price';
}
}
//try to create new div and do all that fun and funky fresh stuff
try {
//create the new div, sets its class, its background, position, and the correct z-index
var newDiv = document.createElement('div');
newDiv.setAttribute('class','selectionBox');
newDiv.setAttribute('style','background-image: url(bgs/' + currentBox + '.jpg);position:absolute;left:' +
document.getElementById(parseInt(currentBox) - 1).style.left * currentBox + 'px;top:' +
document.getElementById(parseInt(currentBox) - 1).style.top * currentBox + 'px;z-index:'
+ 10-currentBox + ';');
//create h2 header
var newHeader = document.createElement('h2');
newHeader.setAttribute('style','margin-top:0px;margin-left:5px;');
//create new text element
var newText = document.createTextNode(divvys[parseInt(currentBox)]);
//puts text into the h2 tag
newHeader.appendChild(newText);
//puts h2 in new div
newDiv.appendChild(newHeader);
//creates new selection box
var newSelect = document.createElement('select');
newSelect.setAttirubte('style','position:absolute;left:25px;top:45px;');
newSelect.setAttribute('onchange','constructor(this.value)');
//creates the first, selected option
var option1 = document.createElement('option');
option1.setAttribute('SELECTED');
var text1 = document.createTextNode(selectionTitles[parseInt(currentBox)]);
option1.appendChild(text1);
newSelect.appendChild(option1);
//selects correct data array from category var defined earlier and pushes everything into options
for(i=0;i<eval(category).length;i++){
var option = document.createElement('option');
var text = document.createTextNode(eval(category)[i]);
option.appendChild(text);
newSelect.appendChild(option);
}
//appends select box to new div
newDiv.appendChild(newSelect);
//appends new div to page
document.body.appendChild(newDiv);
newDiv.setAttribute('style','background-image: ' + eval(count) + '.jpg');
}
catch(e){
alert("The following error occurred: " + e);
}
}
function raiseCount() {
if(GetCookie('count') == null){
//if the count cookie doesnt exist, set it to 1
SetCookie('count', 1);
}
else{
var currCount = GetCookie('count');
count = parseInt(count) + 1;
SetCookie('count',count);
}
}
//function that uses the count cookie to set the proper cookie
//needed with each instance of calling constructor
function setMyCookie(x){
if(GetCookie('count')==null){
SetCookie('abs_brewery',x);
}
else if(GetCookie('count') == 1){
SetCookie('abs_price',x);
}
else if(GetCookie('count') == 2){
SetCookie('abs_brand',x);
}
else if(GetCookie('count') == 3){
SetCookie('abs_finalSelection',x);
}
}
function moveDiv(){
//distance to move
var distance=2;
var n6, ie;
//detect browser
if(document.all){
ie=true;
} else if(document.getElementById){
n6=true;
}
var intervalID=setInterval("doIt()", 6);
function doIt(){
var pos = parseInt(document.getElementById(currentBox).style.top);
var end = parseInt(document.getElementById(currentBox).style.top) + 126;
if(pos > end){
document.getElementById(currentBox).style.top=parseInt(document.getElementById(currentBox).style.top)+distance+"px";
}
else{
//do nothing, its already in the right position
}
}
}
html -- index.html
Code:
<html>
<head>
<title>American Beer Selector</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript" src="constructor.js"></script>
<script language="javascript" type="text/javascript" src="data.js"></script>
<style type="text/css">
body {
background-image:url('bg.jpg');
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
}
.selectionBox {
position: absolute;
top: 100px;
left: 100px;
background-color: #ec5e00;
color: #000000;
width: 300px;
height: 100px;
border: 2px #666666 solid;
vertical-align: top;
z-index: 10;
}
</style>
</head>
<body>
<div id="0" class="selectionBox" style="background-image:url('bgs/0.jpg');">
<h2 style="margin-top:0px;margin-left:5px;">Select a Brewery:</h2>
<select style="position:absolute;left:25px;top:45px;" onChange="constructor(this.value);">
<option selected>-- Brewery Choices --</option>
<option value="ab">Anheuser Busch</option>
<option value="cb">Coors Brewing Company</option>
<option value="mb">Miller Brewing Company</option>
</select>
</div>
</body>
</html>
-
nevermind... that was stupid. im good so far.
-
Why? 
By the way does maybe anyone know.. I had an error in IE 5.0 - couldn't open any javascripts if they available on the web page.
-
 Originally Posted by DakDarie
Why? 
By the way does maybe anyone know.. I had an error in IE 5.0 - couldn't open any javascripts if they available on the web page.
Some more information?!?
Happiness is good health and a bad memory.
-
 Originally Posted by aniseed
Some more information?!?
I find a link (somewhere on a page), move the mouse on it and see in the left bottom corner of the webpage (I use IE 6): "javascript "some text here"". If I click this link, page won't open. I can't open such pages. And I don't get where is the problem, I've tried to reinstall my IE, that doesn't help.
Thanks.
-
I wouldn't worry about it not working in IE5 no one uses that anymore.
-
In fact i think it as low as 1.25% so not worth the trouble.
Last edited by stokelake; 07-02-2006 at 03:07 PM.
Similar Threads
-
Replies: 0
Last Post: 12-31-2002, 11:38 AM
-
Replies: 0
Last Post: 10-30-2002, 04:39 AM
-
By substring in forum VB Classic
Replies: 2
Last Post: 07-24-2001, 02:29 PM
-
By tyris in forum VB Classic
Replies: 6
Last Post: 02-01-2001, 02:08 AM
-
By tyris in forum Database
Replies: 2
Last Post: 01-24-2001, 01:45 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks