Skip to content Skip to sidebar Skip to footer

How To Link To Another Php Page Using Onclick Event From Javascript?

I am currently having issues with making buttons based on an array of information on customers. I have made the buttons in the following way: foreach($array as $row) {

Solution 1:

Why do you need JavaScript at all for this? Why don't you create a normal link which also works if JavaScript is disabled?

<?php foreach($array as $row): ?>
    <tr>
        <td><?php echo $row['last_name'] ?></td>
        <td><?php echo $row['first_name'] ?></td>
        <td><?php echo $row['phone_no'] ?></td>
        <td><?php echo $row['date_of_birth'] ?></td>
        <td><?php echo $row['membership'] ?></td>
        <td><a class='resultBookButton' 
               href="<?php printf("ssreservation.php?lastName=%s&firstName=%s&phoneNum=%s", $row['last_name'], $row['first_name'], $row['phone_no']) ?>"
            >Reserve</a>
        </td>
    </tr>
<?php endforeach; ?>

If you want the appearance of a button, you can use CSS to style the link as button:

a {
    color: black;
    padding: 5px;
    border: 2px outset lightgrey;
    background-color: lightgrey;
    text-decoration: none;
}

a:active {
    border-style: inset;
}

DEMO


Solution 2:

try this..

window.location.href = "ss reservation.php?lastName=" + lastName + "&firstName=" + firstName + "&phoneNum=" + phoneNum;

Post a Comment for "How To Link To Another Php Page Using Onclick Event From Javascript?"