mercredi 12 septembre 2018

passing function parameter to another function by onclick in javascript

i am creating message sending functionality in which there will be posts in a page and with every post there will be send message button on which the user will click and send message form will appear and also on this button i have a function "sendMessage(to_user_id)" which i m calling onclick and after writing the message when send button of the form is clicked the message will be send ..it is working fine but the problem is that with every post there is a "to_user_id" parameter which i m passing to a function by onclick on button but the send message form is one then how will the form get the to_user_id parameter of each user on which the send message button is clicked PS : sendMessage button which will be with every post and send button which will be of the form submit button ...any kind of help will be appreciated. thank you

php :

while($rec = mysqli_fetch_array($query)){?>
<div class="posts" id="postId<?php echo md5($rec['emerId']); ?>">
<div class="row">
<div class="col-md-3 col-sm-4 col-xs-4 pic-cont">
<div class="name-pic">
<img src="serverphp_files/profile_pics/<?php echo $rec['profile_pic'] ?>" width="50" height="50" />
<span class="name"><?php echo $rec['username'] ?></span>
</div>
</div>
<div class="col-md-9 col-sm-8 col-xs-8">
<div class="post-body">
<h3><?php echo $rec['title'] ?></h3>

<p class="more mymore<?php echo $moreval; ?>">

<?php echo $rec['emergency_description'] ?>
</p>
<div class="btn-message"><button onclick="sendMessage(<?php echo $rec['userId']; ?>)"  class="myMsg btn btn-default">Send Message</button></div>  
</div>

send Message Form:

<div class="message-send-form" id="send-msg-form">
<div class="inner-form-message">
<div class="inner-content">
<textarea id="msg-text" cols="10" rows="8" placeholder="Write Your Message"></textarea><br />
<button id="send-btn" class="btn btn-default send-btn" type="button">Send</button>
</div>
<div>

javascript(jquery) :

function sendMessage(to_user){
    $('#send-msg-form').css('display','block');
    if($('#send-btn').click()){
        showMe(to_user)
        }

    }




Aucun commentaire:

Enregistrer un commentaire