Jump to content

Display submit button after input in a TEXTAREA


LoneStarJack

Recommended Posts

I can't get the desired results with this code

 

<script>

$(document).ready(function(){

    $('#btn').css('visibility','hidden');

  });

$('#ta').onkeypress(function(){

    if($(this).val != ''){

      $('#btn').css('visibility','visible');

    };

    });

</script>

</head>

 

<?php

 

if (!isset($_POST["sql"])) {

echo '<body onload="document.forms[0].elements[0].focus()">';

echo '<div id="formx" >';

echo "<h2>Dump Query Records</h2>";

echo '<form action="dump_query_records.php" method="post">';

echo 'Cut and paste sql statement' . '<br>';

echo 'SQL : ';

echo '<textarea id="ta" cols="65" rows="6" ></textarea>';

echo "<br>";

echo '<input  ID="btn" type="submit"  value="Submit SQL!" >  </input>';

echo '</form>';

echo '</div>';

exit();

};

?>

Link to comment
Share on other sites

That's because onkeypress() is a javascript event that is attached to HTML elements. But $("#ta") is a jquery object, not an HTML element. To attach an onkeypress event listener to the element referred to in a jquery object, you use .keypress(), not onkeypress().

Link to comment
Share on other sites

Wouldnt focus work better?

 

<script>
$(document).ready(function(){
    $('input#btn').hide();
      $('textarea[id="text"]').focus(function(){
          if($(this).val().length > 10) {
               $('input#btn').show();
          } else {
              $('input#btn').hide();
          }
   });
});
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.