0

Im trying to pass some values into a text box from a child page to the parent page. The code I have works fine passing one integer value through to the parent page, however it won't pass a string. I also want to try and pass another value through to an additional text box, how would I go about doing that?

logRequestAdmin is the name of the form on the parent page, and ClientName is the text box to post the first value to.

Here's my code for the child page:

<head>
<script type="text/javascript">
    <!-- Begin
    function moveData(info) {
    window.opener.document.logRequestAdmin.ClientName.value = info;
    self.close();
    return false;
    }
    // End -->
</script>

        <table>
            <tr>
                <td class="clientTop">Client ID</td>


                <td class="clientTop">Client Name</td>

                <td class="clientTop">Username</td>

                <td class="clientTop">Email</td>

            </tr>


            $query = "Select * from clients"; 

            $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());  

            while($row = mysql_fetch_array($result))
            {

                $ClientID = $row['ClientID'];

                $ClientName = $row['ClientName'];

                $Username = $row['Username'];

                $Email = $row['Email'];

                echo '<tr>
                        <td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $ClientID . '</a></td>
                        <td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $ClientName . '</a></td>
                        <td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $Username . '</a></td>
                        <td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $Email . '</a></td>
                      </tr>';       
            }
        </table>
2
  • I did not see php tag before php code started Commented Mar 3, 2011 at 16:24
  • Ive just removed them from the post to try and clean the code up a little bit Commented Mar 3, 2011 at 16:24

1 Answer 1

2

It looks like the problem is in your javascript function call in the A tags. Here is how your code works if you pass integers and strings...

echo '...
          <td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $ClientID . '</a></td>
          <td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientName . ');">' . $ClientName . '</a></td>
      ...';

The above lines write HTML like:

<td class="clientBottom"><a href="javascript:void();" onclick="moveData(1);">1</a></td>
<td class="clientBottom"><a href="javascript:void();" onclick="moveData(The Dude);">The Dude</a></td>

JavaScript thinks you're passing a 1 the first time, and should throw an error on The Dude since the function call is malformed.

If you add some extra apostrophes, it should work just fine.

PHP:

echo '...
          <td class="clientBottom"><a href="javascript:moveData(\'' . $ClientID . '\');">' . $ClientID . '</a></td>
          <td class="clientBottom"><a href="javascript:moveData(\'' . $ClientName . '\');">' . $ClientName . '</a></td>
      ...';

HTML:

<td class="clientBottom"><a href="javascript:moveData('1');">1</a></td>
<td class="clientBottom"><a href="javascript:moveData('The Dude');">The Dude</a></td>

If you want your rows to look cleaner, you could also alter your js function to pass the innerHTML property of the link tag...

<script type="text/javascript">
    function moveData(el) {
        info = el.innerHTML;
        // do something with info...
    }
</script>
...
<a href="javascript:void();" onclick="moveData(this);">Lorem Ipsum</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.