SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object Expected Error (specific code included)--Beginner, help needed.

    Hi all! Well, I'm taking an intro. webmaster (HTML) class at school and JavaScript is just being introduced. The format of the class is a kind of "do-it-on-your-own-by-following-the-book" setup. The homework assignments typically guide you through the process. However, I've followed the steps and I can't seem to get this code to work. I've made sure that all the objects are being referenced correctly, and everything is in the correct case (I hope), and tried removing and adding curly brackets, but I just can't seem to get this code to work. So, instead of mulling over the code for hours on end like I do with C#, I'm just going to save myself the headache and ask for help.

    Code:
    <script type="text/javascript">
    <!--Hide from old browsers
    function scrollingMsg(){
    var scrollMsg = "   ** Remeber, property taxes are due June 15 **   "
    var beginPos = 0
    document.msgForm.scrollingMsg.value = scrollMsg.substring(beginPos,scrollMsg.length) + scrollMsg.substring(0,beginPos)
    beginPos += 1
    	if (beginPos > scrollMsg.length) {
    		beginPos=0
    	}
    window.setTimeout("scrollingMsg()",200)
    }
    
    function validateInput(taxCalc) {
    var mValue = document.taxCalc.aValue.value
    var mValue = parseInt(mValue)
    	if (isNaN(mValue) || ((mValue<=0)) {
    		alert("Assessed value is not a valid entry!")
    		document.taxCalc.aValue.value=" "
    		document.taxCalc.aValue.focus()
    		}
    
    	else {
    		var mhomestead = document.taxCalc.homestead.value
    		var mhomestead = parseInt(mhomestead)
    			if (isNaN(mhomestead) || ((mhomestead<=0)) {
    			alert("Homestead discount is not a valid entry!")
    			document.taxCalc.homestead.value=" "
    			document.taxCalc.homestead.focus()
    			}
    		 }
    
    		else {
    			var mseniorDisc = document.taxCalc.seniorDisc.value
    			var mseniorDisc = parseInt(mseniorDisc)
    				if (isNaN(mseniorDisc) || ((mseniorDisc<=0)) {
    				alert("Senior discount is not a valid entry!")
    				document.taxCalc.seniorDisc.value=" "
    				document.taxCalc.seniorDisc.focus()
    				}
    			 }
    			else {
    				var taxes = calcTaxes(mValue,mhomestead,mseniorDisc)
    				document.taxCalc.propTax.value = taxes
    				 }
    		}
    	}
    }
    
    function CalcTaxes(assessValue,HomeDisc,SeniorsDisc) {
    var newAssessedValue = assessValue - HomeDisc - SeniorsDisc
    var propTaxes = newAssessedValue * .0309
    propTaxes = Math.round(propTaxes*100)/100
    return propTaxes
    }
    //-->
    </script>
    I apologize if it's a bit difficult to read. I'm pretty sure that the problem lies within the bold coding.

    Edit: I don't know if it will help, but here is a link to the website.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    error messages

    Hi DarkMusician, welcome to the forums,
    If you're going to be working with javascript, you should get familiar with your browser's javascript error console. For example Firefox shows
    Error: missing ) after condition
    Source File: http://student.claytonstate.net/~csu...tsk1401/lab19/
    Line: 23, Column: 36
    Source Code:
    if (isNaN(mValue) || ((mValue<=0)) {
    and
    Error: scrollingMsg is not defined
    Source File: http://student.claytonstate.net/~csu...tsk1401/lab19/
    Line: 1

  3. #3
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the help. I didn't know Firefox has the Error console. I played around with that and wound up messing with the parentheses. Then I noticed I hadn't closed the nested If...Else statements correctly. I also had the variables for the scrollingMsg() in the wrong area. After fixing all those errors I was still getting a function undefined message for the calcTax function. I decided to just transfer the arithmetic into the last else statement and everything seems to work now.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    style

    I don't know if it has anything to do with the error, but I like to end my statements with semi-colons. eg
    function _blah(arg)
    {
    arg = arg + arg;
    return arg;
    }

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have:
    function CalcTaxes(assessValue,HomeDisc,SeniorsDisc) {

    but you are calling:
    var taxes = calcTaxes(mValue,mhomestead,mseniorDisc)

    Javascript is case sensitive. Fix the case on the function name and it should work.


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
  •