LoneStarJack Posted December 19, 2011 Share Posted December 19, 2011 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 https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/ Share on other sites More sharing options...
son.of.the.morning Posted December 19, 2011 Share Posted December 19, 2011 css('display', 'none') Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299092 Share on other sites More sharing options...
LoneStarJack Posted December 19, 2011 Author Share Posted December 19, 2011 css('display', 'none') works and so does the visibility fnction, but they will not turn back on with the $('#ta').onkeypress(function(). Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299122 Share on other sites More sharing options...
haku Posted December 19, 2011 Share Posted December 19, 2011 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 https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299129 Share on other sites More sharing options...
jotorres1 Posted December 19, 2011 Share Posted December 19, 2011 I had a similar issue once, and all I had to add was <script language="javascript"> Try it out, see if that helps you. Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299137 Share on other sites More sharing options...
haku Posted December 19, 2011 Share Posted December 19, 2011 That would be <script type="text/javascript">. 'language' has been long deprecated. Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299146 Share on other sites More sharing options...
LoneStarJack Posted December 19, 2011 Author Share Posted December 19, 2011 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'); }; Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299169 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Working example here: http://jsfiddle.net/8dG9N/ Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299222 Share on other sites More sharing options...
LoneStarJack Posted December 19, 2011 Author Share Posted December 19, 2011 Thanks scootstah. Works great. I like your format for your answer. Now I want to work on the contents of the textarea having a length > 10 Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299321 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 What do you mean? Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299342 Share on other sites More sharing options...
LoneStarJack Posted December 19, 2011 Author Share Posted December 19, 2011 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> Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299382 Share on other sites More sharing options...
son.of.the.morning Posted December 20, 2011 Share Posted December 20, 2011 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 https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299651 Share on other sites More sharing options...
LoneStarJack Posted December 20, 2011 Author Share Posted December 20, 2011 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. Link to comment https://forums.phpfreaks.com/topic/253445-display-submit-button-after-input-in-a-textarea/#findComment-1299728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.