Current location: Hot Scripts Forums » General Web Coding » JavaScript » Simple question


Simple question

Reply
  #1 (permalink)  
Old 05-17-04, 05:37 PM
Maniax Maniax is offline
New Member
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Simple question

Hi,
Simple question here. How do you use a variable inside another variable name?

Example:

function enableMe(form,button) {
document.form.button.disabled=false;
}

In this example I would be passing a form name (form), and a button name (button) to the function as an argument. How do you insert those 2 variables into the "document.form.button.disabled=false;" statement? The way it is obviously does not work, because the function looks for a form named "form" and a button named "button" and they do not exist.

If I were to try something like:
"document.[form].[button].disabled=false;"

There is a JScript error about "Object Expected". I'm thinking it's because the [form] and [button] are not evaluated, but I don't know why.

Any advice/help is great!
Many thanks
Maniax
Reply With Quote
  #2 (permalink)  
Old 05-18-04, 04:48 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Good guess, just remove the dots like this:
"document[form][button].disabled=false;"
Reply With Quote
  #3 (permalink)  
Old 05-19-04, 04:48 PM
Chris Hill Chris Hill is offline
Newbie Coder
 
Join Date: Mar 2004
Location: UK
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
you are giving values to them right?

such as:
onClick('something', 'something')
onMouseOver('something', 'something')
onChange('something', 'something')

otherwise it will come back with an error
__________________
<a href="http://www.WhiteHillStudios.co.uk/home.php" target="_blank">White Hill Studios</a> - driving down the cost of web design<br>
<a href="http://www.agscriptz.com" target="_blank">AG Scriptz ii: renaissance</a> - a new dawn or scripting
Reply With Quote
  #4 (permalink)  
Old 08-31-04, 12:47 PM
Maniax Maniax is offline
New Member
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Bah

Hmm been awhile since I've had any problems but all the sudden the method posted above doesn't seem to work on a (what looks like simple) function. Keep getting errors saying I'm missing a ";"...

Code:
function Reset(field) {
	document.category[field]style.backgroundColor='FFFFFF';
}
And the call to the function:

Code:
onKeyUp="Reset('title')"
Something I'm missing here?
Reply With Quote
  #5 (permalink)  
Old 08-31-04, 01:08 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
You've forgotten a . not a ; that is just what the Javascript engine thinks...
Code:
function Reset(field) {
	document.category[field].style.backgroundColor='FFFFFF';
}
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help creating tables in mysql (VERY SIMPLE QUESTION) meaculpa1113 PHP 2 03-26-04 12:32 AM
simple array question jimcart JavaScript 1 03-19-04 05:38 PM
Very simple question regarding getimagesize() mixermanic PHP 0 02-24-04 08:14 AM
question about simple login system magsec4 PHP 5 02-23-04 03:35 AM
simple question? Renée PHP 5 08-07-03 12:54 PM


All times are GMT -5. The time now is 02:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.