How to stop calling function when user click on checkbox

30 Views Asked by At

I have on table row. In table row I have checkbox and many other information. Now, I am supposed to open another page while click on row. But need to perform another function while click on checkbox. Here checkbox is also part of the row hence if i am going to click on the checkbox it will open the another page assigned to on click of row.

<tr onclick="window.location='openticket.php';" class="cursor1">
        <td>
        <div class="classic">
             
        <div class="row ms-2" id="<?php echo $i['id']; ?>" onmouseover="display(<?php echo $i['id']; ?>)" onmouseleave="display2(<?php echo $i['id']; ?>)">
            
            <div class="col-1 mt-1 returnhide" id="hidecheckbox<?php echo $i['id']; ?>" style="display:none;">
            <div class="form-check">
            <input class="form-check-input checkboxcheckvalueofrow" type="checkbox" id="cb<?php echo $i['id']; ?>" name="ticketcheckbox[]" value="<?php echo $i['ticket_id']; ?>">
            </div>
            </div>
        </td>
        
        <td>Database issue</td>
</tr>   

This is my code. Openticket.php page should not open if i click on the checkbox. How to do it?

1

There are 1 best solutions below

0
Tom Herman On

You can add an onClick attribute to the checkbox html element that will Use event.stopPropagation. See the code below with the onClick attribute:

    <tr onclick="window.location='openticket.php';" class="cursor1">
        <td>
            <div class="classic">

                <div class="row ms-2" id="<?php echo $i['id']; ?>" onmouseover="display(<?php echo $i['id']; ?>)"
                    onmouseleave="display2(<?php echo $i['id']; ?>)">

                    <div class="col-1 mt-1 returnhide" id="hidecheckbox<?php echo $i['id']; ?>" style="display:none;">
                        <div class="form-check">
                            <input class="form-check-input checkboxcheckvalueofrow" type="checkbox"
                                onclick="event.stopPropagation()" id="cb<?php echo $i['id']; ?>" name="ticketcheckbox[]"
                                value="<?php echo $i['ticket_id']; ?>">
                        </div>
                    </div>
        </td>

        <td>Database issue</td>
    </tr>