Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 14th, 2006, 08:30 PM
Registered User
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Javascript function call

alright... i have a separate html file with some java in the header and it works for movement.

now... im trying to impliment movement on a different project by editing the same code... and now, it is saying that the doIt() function isnt defined.

heres the html file...
<title>American Beer Selector</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="constructor.js" type="text/javascript" ></script>
<script src="data.js" type="text/javascript" ></script>
<script src="cookies.js" type="text/javascript" ></script>
<style type="text/css">
body {
    color: #FFFFFF;
    font-family: Arial, Helvetica, sans-serif;

.selectionBox {
    background-color: #ec5e00;
    color: #000000;
    width: 300px;
    height: 100px;
    border: 1px #666666 solid;
    vertical-align: top;



<div id="abs0" class="selectionBox" style="background-image:url('bgs/0.jpg');z-index:10;position:absolute;top:100px;left:100px">
<h2 style="margin-top:0px;margin-left:5px;">Select a Brewery:</h2>
<select style="margin-left:25px;" onchange="runThis****(this.value)">
    <option>-- Brewery Choices --</option>
    <option value="ab">Anheuser Busch</option>
    <option value="cb">Coors Brewing Company</option>
    <option value="mb">Miller Brewing Company</option>

heres the javascript file - constructor.js (the one that isnt working currently)
/** file that holds all of the main functions for operation **/
function runThis****(x) {
    //calls set cookie function

    //raise the count, then drop it into a variable for easy use
    var currentBox = GetCookie('abs_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){
                var category = GetCookie('abs_brewery') + GetCookie('abs_price') + GetCookie('abs_brand');
                    var category = GetCookie('abs_brewery') + GetCookie('abs_price');
        else {
            var category = 'prices';

    //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');

        alert("currentBox: " + currentBox);
        alert("left: " + parseInt(document.getElementById('abs' + eval(parseInt(currentBox) - 1)).style.left));
        alert("top: " + parseInt(document.getElementById('abs' + eval(parseInt(currentBox) - 1)).style.top));

        newDiv.setAttribute('style',"background-image: url('bgs/" + eval(currentBox) + ".jpg');position:absolute;left:" + 
                            parseInt(document.getElementById('abs' + eval(parseInt(currentBox) - 1)).style.left) + 'px;top:' + 
                            parseInt(document.getElementById('abs' + eval(parseInt(currentBox) - 1)).style.top) + 'px;z-index:'
                            + eval(10-parseInt(currentBox)) + ';');
        newDiv.setAttribute('id','abs' + eval(currentBox));
        var id = 'abs' + eval(currentBox);

        //create h2 header
        var newHeader = document.createElement('h2');

        //create new text element
        var newText = document.createTextNode(divvys[parseInt(currentBox)]);

        //puts text into the h2 tag

        //puts h2 in new div

        //creates new selection box
        var newSelect = document.createElement('select');

        //creates the first, selected option
        var option1 = document.createElement('option');
        var text1 = document.createTextNode(selectionTitles[parseInt(currentBox)]);

        //selects correct data array from category var defined earlier and pushes everything into options
            var option = document.createElement('option');
            var text = document.createTextNode(eval(category)[i]);

        //appends select box to new div

        //appends new div to page

        //sets up everything to move the box... sets variables and such
        var distance=2;
        var currentBox = 'abs' + GetCookie('abs_count');

        var end = parseInt(document.getElementById(currentBox).style.top) + 126;
        var intervalID=setInterval("doIt(distance,currentBox)", 6);    

        //function that 'does it'
        function doIt(d, cb){
            var pos = parseInt(document.getElementById(currentBox).style.top);
            if(parseInt(pos) < parseInt(end)){
                //do nothing, its already in the right position

        alert("The following error occurred: " + e);

function raiseCount() {
        if(GetCookie('abs_count') == null){
            //if the count cookie doesnt exist, set it to 1
            SetCookie('abs_count', '1');
        else if(GetCookie('abs_count') < 3){
            var currCount = GetCookie('abs_count');
            var count = parseInt(currCount) + 1;


//function that uses the count cookie to set the proper cookie
//needed with each instance of calling constructor
function setMyCookie(x){
    if(GetCookie('abs_count') == null){
    else if(GetCookie('abs_count') == '1'){
    else if(GetCookie('abs_count') == '2'){
    else if(GetCookie('abs_count') == '3'){

... and here is the html file with the infile java that DOES work
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html lang="en">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">

    <script type="text/javascript" language="javascript">
    //distance to move
    var dx=2;
    var win_width;
    var n6, ie;

    //detect browser
    } else if(document.getElementById){

    //Get dimensions of the window
    function dimensions() {
       } else if(ie) {


    var intervalID=setInterval("doIt()", 10);

      function doIt(){

        var pos=parseInt(document.getElementById('move').style.left);
        if((pos<win_width && dx>0) || (pos>0 && dx<0)){

        } else {


<body onload="dimensions();" onresize="dimensions();">
<div id="move" style="font-size:72px; position:absolute; left:10px; top:10px;">
  Move Me!
<div style="position:absolute; left:10px; top:200px;">
  <button onclick="intervalID = setInterval('doIt()', 10);">Start!</button>
  <button onclick="clearInterval(intervalID)">Stop!</button>
any help is appreciated guys... ive been tryin to fix this for hours and just cant see where im going wrong. thanks in advance!

Old January 15th, 2006, 04:27 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

It's a bit hard to see, so I could be wrong, but it looks like you nested the doIt function inside the runThis**** function:
function runThis****(x) {
  // implementation of runThis here

  function doIt(d, cb){
    // implementation of doIt here
Instead of this, move doIt outside the runThis method:
function runThis****(x) {
    // implementation of runThis here

function doIt(d, cb){
  // implementation of doIt here
Hope this help,s

Imar Spaanjaars
Everyone is unique, except for me.

Similar Threads
Thread Thread Starter Forum Replies Last Post
stop current javascript function using javascript sakthi Javascript 3 June 2nd, 2008 03:30 PM
Call to function Awkuzu BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 19th, 2007 06:13 PM
Call C++ function from C#.NET ashooagarwal .NET Framework 1.x 0 May 24th, 2007 10:47 PM
Call a Function stealthdevil Access VBA 2 November 2nd, 2006 10:38 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.