Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass html textbox value to a javascript function

I have a HTML textbox where user will input some string which i want to pass to a JavaScript function:

<input type="text" id="ad_search_query" style="width:295px">&nbsp;
<input type="button" value="<s:text name="button.search"/>" class="p-userButton"
 onClick="ADSEARCHGF.showTable('');"/> 

Please suggest how can i do it.

like image 689
Tanu Avatar asked Apr 17 '26 03:04

Tanu


2 Answers

If the event is raised by the button, you will not have the text input object to pass to the function without getting it first, getting it by id is the best way.

You can use the id of the text box:

var searchValue = document.getElementById('ad_search_query').value;

in your function, or use Ahsan Rathod's method to use this code as parameter.

like image 71
StuperUser Avatar answered Apr 18 '26 17:04

StuperUser


<script>
function showTable(obj){
alert(obj.value)
}
</script>

<input type="text" id="ad_search_query" style="width:295px">&nbsp; 
<input type="button" value="search" class="p-userButton" onClick="showTable(document.getElementById('ad_search_query'));"/>
like image 24
fatnjazzy Avatar answered Apr 18 '26 17:04

fatnjazzy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!