#1
  1. I am still learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Kuala Lumpur, Malaysia
    Posts
    249
    Rep Power
    13

    php form variable like in JavaScript


    I tried to pass the form object to a JavaScript function but JavaScript doesn't seems to like the idea of PHP form name conjunction.

    I name my form variables as followed:

    PHP Code:

    <script language="JavaScript">
        function 
    doThis(frObj){
            
    alert(frObj.name);
        }
    </script>

    <table>
    <tr>
    <td><input type="text" name="fr[1][name]"></td>
    <td><input type="text" name="fr[1][age]"></td>
    <td><input type="text" name="fr[1][gender]"></td>
    </tr>
    <tr>
    <td><input type="text" name="fr[2][name]"></td>
    <td><input type="text" name="fr[2][age]"></td>
    <td><input type="text" name="fr[2][gender]"></td>
    </tr>
    <tr>
    <td><input type="text" name="fr[3][name]"></td>
    <td><input type="text" name="fr[3][age]"></td>
    <td><input type="text" name="fr[3][gender]"></td>
    </tr>
    <tr>
    <td>
    <input type="button" value="button 1" onClick="doThis(fr[1][name])">
    </td>
    <td>
    <input type="button" value="button 2" onClick="doThis(fr[2][name])">
    </td>
    <td>
    <input type="button" value="button 3" onClick="doThis(fr[3][name])">
    </td>
    </tr>
    <table> 
    .. and the error message is: fr is undefined....






    any advises?
    I have yet to find the right way to do it.

    www.genedavinci.com
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Try:
    Code:
    doThis(document.form_name['fr[1][name]'])
    Last edited by bricker42; January 27th, 2003 at 06:04 AM.
    -james

IMN logo majestic logo threadwatch logo seochat tools logo