Search code examples
javascriptphpjquerytextboxparameter-passing

How to pass text box value as argument in jquery function on click event


I want to get a value of text box on click as parameter

<input type="text" id="remark_mention" />

// link is here for click

<a class="remark  "href="javascript:void(0);"style="text-decoration:none;color:#d90000;" id="st_mention<?php echo strip_tags($row["pid"]); ?>" onClick="mention_or_remmove_remarks('<?php echo strip_tags($row["pid"]); ?>','st_mention');"> Mention</a>

My jquery function is follow

function mention_or_remmove_remarks(mention_id, action){
    var dataString = "mention_id=" + mention_id + "&action=mention_or_remmove_remarks";//ajax code here for post mention_update.php 
}

How I get a value of textbox in link Onclick event


Solution

  • You can get it by.

    Use form and get it:

    <form>
     <input type="text" id="remark_mention" name="remark_mention_ID"/>
    <input type="button" onclick="foo(this.form.remark_mention_ID.value)"/>
    </form>
    

    OR :

    <input type="text" id="remark_mention" />
    

    and in your js file :

    var value = $('#remark_mention').val(); // value variable has your latest value