Jump to content

Disabling A Button Until Text Boxes Filled


Viper114

Recommended Posts

Is there an easy way to keep the button used to submit a form disabled until the necessary text boxes are filled with info? For example, the First Name box is coded like this: <input type="text" name="fname" onchange="validatePresent(this, 'inf_fname');"><span id="inf_fname">Required</span></td> On the public page, this basically shows the word Required right next to the text box until it is filled, then it disappears. This is the same across all the text boxes on the form. How can I code the Submit button so that it remains disabled until these boxes are filled? And something a bit more advanced but less important, can it also be disabled until some drop down menus are changed from their default selections of "Please choose one"? I've been reading up on this and the only things I could find were people suggesting to use Javascript to do this, but I don't know Javascript myself. If it can't be easily done in HTML, then we don't need to worry about this too much.

Link to comment
Share on other sites

You can withhold any prompt you'd like for any reason you choose. Javascript is the way I'd go.

Link to comment
Share on other sites

But how exactly? I've never done it before, so I need help in doing so. If there are a number of text boxes like the example I gave, and a Submit button with the code: <input type="submit" name="submitbtn" value="Submit"> What would I need to do in order to make the submit button stay disabled until the text boxes are filled?

Link to comment
Share on other sites

Do you just need it filled or filled correctly and accurately. I think you're about to learn why prompts are frequently not withheld. For example. take something that should be simple like input for firstname. Would you accept the input: "xyz"? That will fill the input box, but I'm sure it's not what you want. The point is, if you're going to force an input you'll get a lot of garbage unless you've built someway to validate every input. Validation is a whole other issue that's relevant if you force input.

Link to comment
Share on other sites

For now, just filling it in with anything would work. I just want to avoid having fields completely anything, which causes problems overall than just garbage text. Then it's just a case of the people receiving the info manually sorting it out and tossing whatever is actually garbage.

Link to comment
Share on other sites

OK. If was you, I'd want to choose between Javascript or PHP for the project. How would you decide?

Link to comment
Share on other sites

I get that, but you should know what you're giving-up. I was like you. When I learned the big advantage of JS I became a fan (although I still do most things in PHP). Hint: it has to do withthe difference between browser and server scripting.

Link to comment
Share on other sites

Just get around to it when you get the chance. The answer changed my entire point of view on coding. So, what's your general plan for this code?

Link to comment
Share on other sites

The general idea is that until the 7 textboxes that are marked Required on the public page are filled in, the Submit button at the bottom is disabled, so the page doesn't process blank text boxes that ultimately leads to problems with the order overall. And since each order is handled manually once they've been submitted, it doesn't matter what the textboxes are filled with, as the people can generally figure it out themselves or call the person behind the order for more info. As long as something is in the textboxes upon submission so that errors are avoided, that will be fine for us.

Link to comment
Share on other sites

I first thought it would be the Required word at the end of each of those boxes, since the page was designed to show them until the box was filled, at which point it would disappear. If not, then I suppose as long as there is a value in the textboxes (regardless of what it is), that should work as the trigger as well.

Link to comment
Share on other sites

You're right, but all of a sudden we're getting away from PHP and moving towards javascript. That's more than OK. You have to get your data into a variable or array and I can't think of a way to do that with PHP without a submit button. I can with js. What do you want to do?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...