Jump to content

[SOLVED] Disable SUBMIT until textarea is populated


BigMonkey

Recommended Posts

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

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.