jquery get the input box value -
i have multiple text boxes , trying value of text boxes based on button click, , value of text box should shown.
// html code here <div class="addtext"> // input box value <input type="text" id="textval" placeholder="enter text" class="enter-text" name=""> // div of buttons add , update text <div class="buttonset"> // add button <button id="addtextbtn" class="left">add text</button> // update button <button id="updatebtn" class="right">update text</button> </div>
// below code tried not able previous text box value // button click event here jq('body').on(opc_eventtype, '#addtextbtn', function() { // getting text box value here var val = jq(this).prev().prev("input[type=text]").val(); // print on console console.log(val);
first of need use .parent().prev()
target input element.
second, if want work click event, use .on("click", '#addtextbtn', function()
third, opc_eventtype
?
var jq = $; // button click event here jq('body').on("click", '#addtextbtn', function() { // getting text box value here var val = jq(this).parent().prev("input[type=text]").val(); // print on console console.log(val); })
working demo
var jq = $; // button click event here jq('body').on("click", '#addtextbtn', function() { // getting text box value here var val = jq(this).parent().prev("input[type=text]").val(); // print on console console.log(val); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="addtext"> <input type="text" id="textval" placeholder="enter text" class="enter-text" name=""> <div class="buttonset"> <button id="addtextbtn" class="left">add text</button> <button id="updatebtn" class="right">update text</button> </div>
Comments
Post a Comment