Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    By@
    By@ is offline
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Pass this to the function.
    Code:
    onblur="myFunction(this)"
    ...
    function myFunction(obj){
      alert(obj.value);
      obj.value = ""; //reset
      alert(obj.value);
    }

  • #3
    By@
    By@ is offline
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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
    }

  • #5
    By@
    By@ is offline
    New Coder
    Join Date
    Sep 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ohhh! Sorry. Im an idiot. Thankyou so very much.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •