Viper114 Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 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 More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 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 More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 Might as well stick with PHP, as the majority of the website is built with it and MySQL. If necessary, I can provide the necessary code this all pertains to. Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 I understand, but just for the record, what do you give up going the PHP route? Link to comment Share on other sites More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 I'm not too certain. I know a decent amount of PHP (but not fluent like some people here) but I've never worked with Javascript before. Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 Well, I won't say no if Javascript would be the better way to go. I'm not opposed to learning something new. I just figured at first PHP would make more sense since the site I work with is built with PHP. Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 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 More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 What are you going to use as your trigger? Link to comment Share on other sites More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 So, basically, with the second trigger method, it would basically go like: If fname, lname, email, phone, address, city and postalcode have values Submit button is enabledElse Submit button is disabled Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 OK, but how will you trigger the enabling of the submit button? Link to comment Share on other sites More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 How about by checking the text boxes for any values regardless of what they actually contain? Having no information causes a lot more problems than having useless information. Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 Yes, but how will you check them without submitting the data in the boxes first? Link to comment Share on other sites More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 Is there not something like an onchange or similar option that can watch for changes in the textboxes? Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 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 More sharing options...
Viper114 Posted November 21, 2011 Author Share Posted November 21, 2011 Whatever's easier to do. If that involves Javascript, then so be it. Won't hurt to learn something new. Link to comment Share on other sites More sharing options...
niche Posted November 21, 2011 Share Posted November 21, 2011 Good decision. When you have some code please post it in the js forum. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.