Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2005, 02:59 AM   PM User | #1
By@
New Coder

 
Join Date: Sep 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
By@ is an unknown quantity at this point
Variables in paths

Okay.

Im mixing javascript and php and in one section, I use php to draw numerous rows from a database.
Each row is shown in a line of input boxes and on each row, a number in the name is incremented.
Like so...
/-------------------------\
| inputa1 inputb1 inputc1 |
| inputa2 inputb2 inputc2 |
| inputa3 inputb3 inputc3 |
\-------------------------/

Now the problem is, that onBlur, each input field runs a function and sends their name.
myFunction(this.name);

In the function, it does some stuff and then resets the value of the field. But I don't know how to do it because its a variable.

document.myForm.fieldName.value doesnt seem to work because it looks for a field called fieldName instead of the variables actual value.

Any ideas anyone? Theres probably a really simple explanation but I cant seem to find it anywhere

Thanks in Advance
By@ is offline   Reply With Quote
Old 09-20-2005, 04:56 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Pass this to the function.
Code:
onblur="myFunction(this)"
...
function myFunction(obj){
  alert(obj.value);
  obj.value = ""; //reset
  alert(obj.value);
}
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 09-22-2005, 10:00 AM   PM User | #3
By@
New Coder

 
Join Date: Sep 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
By@ is an unknown quantity at this point
This doesnt really help, I need to select the field at the end of the function.
But to do this, I need to use a variable in the path.
By@ is offline   Reply With Quote
Old 09-23-2005, 07:19 AM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
I don't understand you. If you pass this to the function, the function has the pointer to the field. You can call all the field's methods (i.e. focus, select) and properties (i.e. value).
Code:
<input type="text" onblur="myFunction(this)" />
...
function myFunction(obj){
  alert(obj.value); //alert value of field
  obj.select(); //highlight value of field
}
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 09-23-2005, 08:27 AM   PM User | #5
By@
New Coder

 
Join Date: Sep 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
By@ is an unknown quantity at this point
Ohhh! Sorry. Im an idiot. Thankyou so very much.
By@ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:23 AM.


Advertisement
Log in to turn off these ads.