0

I got the following php foreach loop in the A page of my web appliation. And i want to use the $watson variable which is inside this loop in an other php B page. What i did is used this variable as a value in an extra input button:<input type="button"/ value="<?php echo $watson; ?>,so to be able to capture this var in javascript like you see below.

<tbody>
    <?php 
        foreach($records as $r) {
            $watson = $r->case_reference;
        ?>
            <tr>
                <td><?php echo  escape($r->user); ?></td>
                <td><?php echo  escape($r->customer); ?></td>
                <td><?php echo  escape($r->vessel); ?></td>
                <td><?php echo  escape($r->country); ?></td>
                <td><?php echo  escape($r->port); ?></td>
                <td><?php echo  escape($r->eta); ?></td>
                <td><?php echo  escape($r->service_station); ?></td>
                <td><?php echo  escape($r->type_of_service); ?></td>
                <td><?php echo  escape($r->case_reference); ?></td>
                <td><?php echo  escape($r->status); ?></td>
                <td><input type="button" value="<?php echo $watson; ?>" onclick="popEdit(this.value);" /></td>
            </tr>
        <?php
        }
        ?>
</tbody>

The code for the onclick="popEdit(this.value);"function which pops up the B page mentioned above is :

function popEdit(str) {
    window.open("example.php?watson="+str, "pop_edit_jobs",
                 "width=400,height=350,scrollbars=no,left=460,top=400")
}

And the php B page code starts as $ref_num = $_GET['watson']; so i can use the variable.

My problem is that i dont want the input/button in the A page to show the variable on it instead i want it to just show the word EDIT.But to do that i ll have to change its value and then i wont be able to capture this $watson var in javascript.

Any suggestions regarding how to achieve the above effect?

2 Answers 2

2
<td><input type="button" value="EDIT" onclick="popEdit('<?php echo $watson; ?>');" /></td>

should achieve the desired effect.

Sign up to request clarification or add additional context in comments.

1 Comment

This really works like a charm. I am so stupid for not thinking that earlier,guess lack of experience counts.Thanks a lot.
0

Wrap a form around your entire table, then use submit buttons:

<input type="submit" name="watson" value="<?php echo htmlspecialchars($watson); ?>" />

1 Comment

Thanks for your fast reply. Do you mean wrapping the whole table in the A page in a form which will post at the B page via "GET" method and puting $watson=$_GET['watson']; ? This way i can get the $watson var without javascript??

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.