DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2006
    Posts
    2

    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>

  2. #2
    Join Date
    Jan 2006
    Posts
    2
    nevermind... that was stupid. im good so far.

  3. #3
    Join Date
    Feb 2006
    Posts
    6
    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.

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    255
    Quote 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.

  5. #5
    Join Date
    Feb 2006
    Posts
    6
    Quote 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.

  6. #6
    Join Date
    Jul 2006
    Posts
    2
    I wouldn't worry about it not working in IE5 no one uses that anymore.

  7. #7
    Join Date
    Jul 2006
    Posts
    2
    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

  1. JavaScript Math Problem.
    By zack in forum Web
    Replies: 0
    Last Post: 12-31-2002, 11:38 AM
  2. Reliability Problem
    By elise in forum .NET
    Replies: 0
    Last Post: 10-30-2002, 04:39 AM
  3. problem with recordset from Sybase and Oracle
    By substring in forum VB Classic
    Replies: 2
    Last Post: 07-24-2001, 02:29 PM
  4. quote in a string : query problem under VB
    By tyris in forum VB Classic
    Replies: 6
    Last Post: 02-01-2001, 02:08 AM
  5. quote in a string : query problem
    By tyris in forum Database
    Replies: 2
    Last Post: 01-24-2001, 01:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links