View Full Version : Variables in paths

09-20-2005, 03:59 AM

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.

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

09-20-2005, 05:56 AM
Pass this to the function.

function myFunction(obj){
obj.value = ""; //reset

09-22-2005, 11:00 AM
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.

09-23-2005, 08:19 AM
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).

<input type="text" onblur="myFunction(this)" />
function myFunction(obj){
alert(obj.value); //alert value of field
obj.select(); //highlight value of field

09-23-2005, 09:27 AM
Ohhh! Sorry. Im an idiot. Thankyou so very much.