Jump to content

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();

};

?>

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().

I tried both suggestions and combinations thereof and it still was no go.

 

I am wondering about  #ta being a TEXTAREA.

 

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

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

      $('#btn').css('display', 'block');

    };

 

It was easier than I thought.

 

<script>

$(document).ready(function(){

    $('input#btn').hide();

$('textarea[id=text]').keypress(function(){

    if($(this).val().length > 10) {

        $('input#btn').show();

    } else {

        $('input#btn').hide();

    }

});

});

</script>

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>

son.of.the.morning

The keypress, keyup, and keydown allow me to test the length of the field with each key stroke. If the length is greater than 10 the button will be shown. It will also hide the button should the count go below 10.

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.