0

fetch_customer_info.php

<button id=printToTextarea>Get to box</button>

text.php

<?php
require_once('fetch_customer_info.php');
?>
<script type="text/javascript">
$("#printToTextarea").on("click", function () {alert(3);
    $(this).next("#textInput").focus();
 });
 </script>

<div id="projectNameDiv">
    <label for="textInput">Text to Print:</label><br/>
    <textarea name="textInput" id="textInput"  rows='3' cols='40'></textarea>
</div>

When I click the button 'Get to box', no alert message appearing. I need to focus text area.

Muhammad Muazzam
  • 2,810
  • 6
  • 33
  • 62

1 Answers1

2

remove $(this).next() function.

$("#printToTextarea").on("click", function () {
   alert(3);
   $("#text1").focus();
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<textarea name="text1" id="text1" cols="30" rows="10"></textarea>
<button id="printToTextarea">Get to box</button>
noushid p
  • 1,453
  • 5
  • 16
  • 29