BigMonkey Posted July 2, 2007 Share Posted July 2, 2007 Bonjour, freaks! Given the following code, how can I cause the SUBMIT button to be disabled until the user begins to type into the textarea? The idea, of course, is that the textarea is a required entry and leaving it blank results in the inability of the user to submit the form. In this case, I'm using a quasi-pseudo-very-nearly-almost-sort-of dynamic page in which the form action calls the same page and the newly displayed information is based on the SUBMIT button having been clicked (thus giving it a value of TRUE). <?php if ( empty($submit)) { ?> <form action="test.php" method="post"> // this page is test.php -- it calls itself // the textarea is empty here; needs to be populated as a requirement. <textarea name="description" cols="40" rows="12"></textarea> <input type="radio" name="svcType" value="Service" />Service is required<br /> <input type="radio" name="svcType" value="Sales" />Supplies are required <input type="submit" name="submit" value="Send" /> </form> <?php } if (isset($submit)) { // I've been told I should change this to use the $_POST variable // cobble together return message // which is displayed on the "second page" } ?> The examples I've seen on the Internet fora contain heaps of JavaScript and, if there no elegant way to achieve the desired result in PHP, then JScript is just fine. However, I've seen a lot of examples, but none seem to apply to the specific result I desire here. Gently foisted into you collective laps for review, Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 2, 2007 Share Posted July 2, 2007 use the on key press for the text box then use then enable the button u could also count the string tru js before you enable Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 2, 2007 Share Posted July 2, 2007 This can't be done without JavaScript. Why not just check to see if they filled it in after it is submitted? Plus, if the user doesn't have JavaScript enabled, they are going to be able to submit the form with a blank textarea whether you want them to or not. So your going to have to have some sort of error handling when the form is submitted anyways. Quote Link to comment Share on other sites More sharing options...
BigMonkey Posted July 2, 2007 Author Share Posted July 2, 2007 Since this particular form sends the information to itself (action="test.php"), there is no second page. If JS in not enabled on the client machine, then that is the least of my worries, I suppose. But for those whose JS is enabled, I'd like to disable the SUBMIT button. I'm actually using code that was delivered for me to use in production (I think--no, SURE--it was harvested from another site altogether), so I've had to perform some cosmetic surgery on the existing code, plus I'm having to learn more PHP as I go. I smell a redesign... At any rate, if one of you has a snippet of code to demonstrate how I might accomplish this, I would be greatful. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 2, 2007 Share Posted July 2, 2007 Can't you just use an onSubmit + check if the textarea is empty? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted July 3, 2007 Share Posted July 3, 2007 change your form tag(added name= and onsubmit=): <form name="myform" action="test.php" method="post" onsubmit="if (document.myform.description.value){return true;} else {alert('fill in textbox');return false; }" > Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.