Domanda

I am trying to have an onClick event to open each instance of the edit link that links to the specific ID in my database so that you can just click to open a new window edit what you have to and not have to browse away from the main page.

I can get get the link to work in a regular href and a target blank, but with the onclick event it doesn't appear to work properly and I need to set the parameters for the window. I have searched around and tried many solutions to other similar problems but I just can't figure out a solution. Is this even possible?

Here is the snippet of code I'm working with.

    while($row = mysql_fetch_array( $result )) {       
    // echo out the contents of each row into a table
    echo "<tr>";
    echo '<td>' . $row['id'] . '</td>';
    echo '<td>' . $row['lname'] . '</td>';
    echo '<td>' . $row['fname'] . '</td>';
    echo '<td>' . $row['activity'] . '</td>';
    echo '<td>' . $row['guests'] . '</td>';
    echo '<td>' . $row['room'] . '</td>';
    echo '<td><a href="" onClick="window.open("edit.php?id='.$row['id'].',\'mywindow\')">Edit</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '" >Delete</a></td>';
    echo "</tr>"; 

Any assistance on this would be amazing, thanks in advance.

È stato utile?

Soluzione

Try this:

echo "<td><a href='' onClick=\"window.open('edit.php?id={$row['id']},\'mywindow\'')\">Edit</a></td>";
echo "<td><a href='delete.php?id={$row['id']}' >Delete</a></td>";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top