Search code examples
javascriptphpfunctionyiihidden-field

How can i pass 3 parameters in onclick function .The parameters are inside php tag


This is my onclick function:

onclick="InboxDetailsPage('<?php echo $message['id']; ?>')

These are my parameters: threadid,recipient id, and message id

<input type="hidden" id="threadId-<?php echo $message['id']; ?>" value="<?php echo $message['threadId']; ?>"/>
<input type="hidden" id="recipientId-<?php echo $message['id']; ?>" value="<?php echo $message['otherUserRoleId']; ?>"/>
<?php echo $message['id']; ?>

This is where i am using my onclick function:

<div class="inbox">
    <?php $inboxno = 0;
    foreach ($messageList as $message) { ?>
        <?php if ($message['toFromLabel'] == "From") {
            $inboxno++; ?>
            <input type="hidden" id="threadId-<?php echo $message['id']; ?>" value="<?php echo $message['threadId']; ?>"/>
            <input type="hidden" id="recipientId-<?php echo $message['id']; ?>" value="<?php echo $message['otherUserRoleId']; ?>"/>
            <tr class="gradeA odd inbox">
                <td class="" style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?>><?php echo $message['date']; ?></td>
                <td class="" style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?>><?php echo $message['fromName']; ?></td>
                <td class=" " style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?> style="width:300px !important"><?php echo $message['subject'] ?></td>
                <td class="" style="padding-bottom: 1px;"><a type="button" data-toggle="modal" data-target="#myModalq1" class="btn btn-success " onclick="InboxDetailsPage('<?php echo $message['id']; ?>') ">VIEW</a></td>
            </tr>
        <?php }
    } ?>
</div>

Solution

  • You can do the below format:

    onclick="InboxDetailsPage('<?php echo $message['id'];?>', '<?php echo $message['id'];?>', '<?php echo $message['id'];?>')
    

    Alternatively, using just one echo:

    onclick="InboxDetailsPage(<?php echo "'{$message['id']}', '{$message['date']}', '{$message['id']}'";?>)