Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    I am having problems...

    the error i get is
    Error: document.getElementById(array[i]) has no properties
    Source File: http://localhost/FINAL/quotecode.js
    Line: 21
    Code:
    
    detailsamount = 1
    detailsarray = new Array(2)
    detailsarray[0] = 'name';
    detailsarray[1] = 'email';
    i = 0;
    
    function page(now, next) {
    	document.getElementById(now).style.display = 'none';
    	document.getElementById(next).style.display = 'inline';
    }
    
    function check(from, to) {
    error = from + 'error';
    array = from + 'array';
    	if (i > from + 'amount') {
    		i = 0
    		document.getElementById(from).style.display = 'none';
    		document.getElementById(to).style.display = 'inline';
    	
    	} else if (document.getElementById(array[i]).value == "") {
    document.getElementById(error).innerHTML = 
    '<br><b>You have not filled in all the <font color=#006699>required fields</font></b>';
    	
    	} else {
    		i = i + 1;
    		check("'" + from + "', '" + to + "'");
    	}
    }
    basically what this code is meant to do is check if the required text boxes have been filled in, then if it they have it hides that part of the form and shows the next. If not it should show an error message.

    if you really need to see what it is all about i will put it on the web

    thanks
    JR

  2.  

  3. #2
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    Well, I can't quite follow what's going on with the code, but it looks like i tracks which 'page' you're up to, and the error comes from the line
    Code:
    ... } else if document.getElementById(array[i]).value == "") { ...
    So you should change array to detailsarray, because that array holds the names of the 'pages' you're checking one by one...
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  4. #3
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    no - detailsarray is the required text boxes and i is the number of each one in the array...

    i can't change it to detailsarray because i am going to add more arrays for the required parts on each page. 'from' is the page that it is checked and 'to' is the page it will go to. So when an array is checked it will use the 'from' and then array for each page
    JR

  5. #4
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    So each 'page' has a JS array called pagenamearray that has the ID names of each field in that field, and pagenameerror is the ID of the element intended to hold error messages...

    Because you're dynamically getting the name of pagenamearray (array=from + 'array'), you would have to change array[i] to window[array][i] I think, because array is just a string... array[i] will just give you one character of that string.
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    its quite confusing isn't it?

    it worked ...

    now just to fix the rest of the code

    thanks a lot
    JR

  7. #6
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    what is wrong with this?
    [minicode] check("'" + from + "', '" + to + "'");[/minicode]
    JR

  8. #7
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    That's a bit odd, why not:
    [minicode]check(from,to)[/minicode]?

    The check() function takes two params, so you should supply it... they way your calling it is effectively
    check("'thispage', 'nextpage'")...

    Still, I'd be very careful in calling check() from within check. You'll probably get infinite loops... (looking for solution...)
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  9. #8
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    it wouldn't go into an infinate loop because of the if statements...

    it can't be from and to because it needs to get the values of from and to and send it back to the function, therefore it needs the single quotes. I think so anyway.
    JR

  10. #9
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    Actually recursion isn't a problem. The else block it's called from has an i++ statement immediately before it, so the behaviour will be

    If there are errors: It will hilight the first one, and leave the page like that.
    If there aren't errors: It will go to the next page (to).
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  11. #10
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    You also need to change:

    if (i > from + 'amount')

    To

    if (i > window[from + 'amount'])
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:21 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com