简体   繁体   中英

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

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

Html

<input type="text" id="remark_mention" />
<a class="remark "href="javascript:void(0);"> Mention</a>

Js

$('.remark').on('click', function(){
    var text_val = $('#remark_mention').val();
    console.log(text_val);
});

jsfiddle demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM