I need to utilise two 'submit' style of buttons for controlling a piece of equipment which can raise and lower a platform. The 'controls' are to be shwon on a web page which allows an 'operator' to control the equipment. I'd like to have two individual buttons - one for 'Raise' and the other for 'Lower'. Instead of the usual submit command sending the whole form data for everything on a form, is it possible to set-up a form for each button so that when a button is pressed, only the data pertaining to that button is submitted? I'd prefer to have other 'control buttons' such as these two on the same page, so maybe a form per button is required? Thanks for any help!
So what you basically need is several buttons on a page, each time one is clicked it sends a little information to your server telling your equipment what to do? For example you have 2 buttons: Up clicked - Command 'UP' sent to server. Up clicked - Again, command 'UP' sent to server. Down clicked - Command 'DOWN' sent to server. Something like that? If I understood your scenario correctly, first of all this is the wrong category to post in! CSS is to do with the visual presentation, not functionality. Looking at what you need it'd probably be best to go down the AJAX road, so you'd be better off posting in the JavaScript category. With AJAX you'd be able to make the buttons send the command to your server without having to load a new page each time, which I think will suit your needs. I would help further except JavaScript is not my strong suit!
I always laugh when I see responses like Darkhodge's here... (No offense). Let's dive right for the javascript- NOT. <input type="submit" name="upperSubmit" value="First Submit" /> <input type="submit" name="lowerSubmit" value="Second Submit" /> Code (markup): then server side: if (!empty($_POST['upperSubmit'])) { /* first one was pressed */ } else if (!empty($_POST['lowerSubmit'])) { /* second one was pressed */ } Code (markup): Works like a charm. You keep the markup simple and practice separation of presentation from content that will/should load as fast and clean as ANY AJAX solution. The entire form will be submitted, but you will know what button was pressed. You can also make them all the same name: <input type="submit" name="multiSubmit" value="First Submit" /> <input type="submit" name="multiSubmit" value="Second Submit" /> Code (markup): and then check $_POST['multiSubmits'] for it's value. The one clicked is the value sent. First technique is more useful if they are all going to show the same text. But that's something few people realize - you can have and track multiple submit buttons from one form and track them server side.
Sounds good! Thanks for your help. It shows how much of a newbie I am - I even posted to the wrong place. The page will also contain two radio button groups, so I'm thinking that these would also be 'refreshed' when the form information is submitted? I've not heard of AJAX before, so I'll need to do some reading - but I like the given solution also as it uses syntax that I am reasonably familiar with without having to learn something new. Every new thing I learn pushes-out some old stuff that I learned before..... Thanks again!
Usually, yes, a page is refreshed after a form submission. However, you can have a session running on the server which keeps track of what the user has chosen, similar to what you see on forms that present you a new form with your pre-filled information that you submitted but came back to you because of an error: you didn't have to re-fill in all the other values because the server was keeping track of those values for you. There are a few ways to do this, including using cookies. AJAX, since you say you've not heard of it, is a football team from Rotterdam. Ok, it's also not much more than Javascript who sends data to and takes data from the server and can update the content of a web page without requiring a page refresh. Originally it was meant that the data was in XML format (the X in AJAX) but you can apparently have any data format, including JSON or YAML or whatever. While this is awesome and may be able to save trips to the server (and may be faster if the server is slow in handling requests), it's still basically Javascript, which means you will have users who cannot run it (unless you are building for an intranet and can set what people use to reach this page). If you choose to look further into AJAX, be aware that it's best used as a sugar on top of server-side scripting... and you may want to read Chris Heilmann's article at SmashingMag about good practices: http://www.smashingmagazine.com/2010/01/21/find-the-right-javascript-solution-with-a-7-step-test/
Uhm... no need for a 'session', cookies or server side tracking. All the information filled out on the form is sent via $_POST, so just echo it out again! End of problem. No actually, it's the same number of trips since the javascript STILL has to send a request to the server and then sit there with it's thumb up it's ass waiting for it to respond. Which is why if you are going to waste AJAX on something simple like a form, you should have a 100% identical functionality fallback that doesn't require it. Biggest rule of javascript - it should ENHANCE functionality, not supplant it. Interesting little article. His first four items mimics my own views - though after that it goes downhill a bit but I'm one of the people who doesn't see much merit in off the shelf scripts and thinks that javascript 'frameworks' are 99% of what's WRONG with scripting today. Fat bloated trash like jquery or mootools making fatter, slower, more complex and difficult to debug scripts; in the name of making it simpler?!? - that's the part I really don't get about all that asshattery... It's MORE complex and MORE code, how the blue blazes do people find it 'easier' or 'simpler'?!? Because some yank-hole wrote a book about it?
Is that safe? I mean, when it's info like credit card numbers and the such? A separate request?? This confuses me from other stuff I've read. Several yank-holes. Basically the idea is, everyone ends up making their own libraries anyway: making a getElementsByClass, making a hasClass, addClass, removeClass. Making a document.getElementBytId("blah") that's not a bazillion characters long (what was the w3c thinking? Maybe they were thinking "Java"?). Making crossbrowser stuff like eventloaders that work in IE... so several people had the same idea at once: why not publish one and let other people use it? Mootools is an extension of Javascript. The stuff Mozilla's been adding to JS, Mootools has: let, forEach, stuff mature programming languages have had for years and JS was just so poorly designed as to not have it when it should have. Plus who knows what other stuff, I've never dug into MT, but if I ever got an employer who insisted I use a lib, that's the one I'd use. I can't count the number of times someone has recommended a library for something small and silly like dropdown menu sugar or adding some stuff to a textarea in a form or for a lightbox... that's just typical abuse you see anyway. But remember Heilmann (and Crockford) work for Yahoo, and you can see Yahoo is big into libraries and CSS "frameworks" (really don't see the point of those, but whatever, they keep people happy).
HTTPS works both directions - it's no less safe than sending it to the server in the first place. When you trigger AJAX, it has to send the new information to the server and recieve new information from the server - so it's no more or less requests to the server than if you just reloaded the whole page. Though I've seen that same arguement by people using the technology without even understanding how it works. Because most of it is redundant and/or not even used - much less makes bigger code? It's rubbish pure and simple. The very notion of complex libraries in a INTERPRETED language that's transmitted over a narrow pipe is absurd. Oh yes, let's go back to 4k level one ROM basic, NOT. Already exists, just not called that and doesn't work with objects, only arrays; "For var i in elements" I believe. You mean stuff COMPILED languages have where you can optimize all those complex constructs on the fly. Javascript much like line numbered basic is an INTERPRETED language running inside a browser. Sacrifices were made to keep it SIMPLE and FAST within those limitations... as evidenced by it being usable under Nyetscape 4 on a 386/40. Which is why they have a fat bloated bullshit website nobody wants to use apart from 'groups'. As Stephen Colbert said on "the word" - I for one am shocked, Yahoo still has customers? <word>google it!</word> http://www.colbertnation.com/the-co...82/december-16-2009/the-word---spyvate-sector You know, 931k to deliver 3k of text and six content images? 388k of that javascript and 260k of CSS - FOR THAT?!? Fargin Angust it's 156k of HTML for 3k of text... They could probably start showing in the black if they would just learn to write HTML properly since they could probably throw away two thirds of their hosting. To tack on to dan's little rant, the only thing you can learn from Yahoo is how not to build a website. Going to them for advice on web development is like going to Snoop Dog for advice on abstinence from drugs.
Useless for arrays. Absolutely worthless, doesn't go in order, doesn't stay in the actual object you're even going through (will go through ancestor properties). Either write your own forEach, or use Mozilla's and then write your own for all the other browsers, or don't go through arrays. Or if you wanted to go through the name/keys for any reason. JS has design flaws and frankly that's one of them. So far as I know, forEach or for..in isn't in C or C++. Funny, interpreted languages DO have it. In any case there's no way I will be able to do any decent functional programming without first having my bagO'functions sitting ready at the hand. Only using my own because I'm learning and I don't believe students of a language should be relying on someone else's libraries as black boxes.