01hanstu Posted September 6, 2010 Report Posted September 6, 2010 Hi, Wondering if someone can help! I need to be able to create a button on my page to clear all the text field on the page. Part of my code is: $i = 1; while ($i < 7) { Then the field name are named mon$i (Where i loops) Just wondering if anyone know where to start with this? Regards -Stuart
EduTech Posted September 6, 2010 Report Posted September 6, 2010 Does this help: Usability Tip: RESET Button and Forms James.
01hanstu Posted September 6, 2010 Author Report Posted September 6, 2010 Hi, Unfortunatly this doesnt work. The fields are generated by php (through the loop). Regards, - Stuart
EduTech Posted September 6, 2010 Report Posted September 6, 2010 oh right! dunno then I'm dense when it comes to PHP etc. unless it's basic Sorry
01hanstu Posted September 6, 2010 Author Report Posted September 6, 2010 Yeah - me too. Pickup the useful stuff ... ditched the rest
EduTech Posted September 6, 2010 Report Posted September 6, 2010 yeah the pro's will be here soon enough! lol
powdarrmonkey Posted September 7, 2010 Report Posted September 7, 2010 Wondering if someone can help! I need to be able to create a button on my page to clear all the text field on the page. Part of my code is: $i = 1; while ($i < 7) { Then the field name are named mon$i (Where i loops) That's all of it??? That snippet won't even compile. (don't use short-form PHP delimiters, by the way.) Just wondering if anyone know where to start with this? An HTML reset button in your form. This is not a job for PHP.
localzuk Posted September 7, 2010 Report Posted September 7, 2010 This is a job for either a reset button, or Javascript. There's no need for the server side to be doing anything to client-side information.
01hanstu Posted September 7, 2010 Author Report Posted September 7, 2010 Hi Guys, I havce tried this and it does not work. I added a reset button, but on the page it doesn't do a thing! Regards - Stuart
localzuk Posted September 7, 2010 Report Posted September 7, 2010 Hi Guys, I havce tried this and it does not work. I added a reset button, but on the page it doesn't do a thing! Regards - Stuart Can you post a more complete code listing? ie. the code for your page?
pkkelly Posted September 16, 2010 Report Posted September 16, 2010 $i = 1; while ($i < 7) { $text .= "mon" . $i $i++; } I'm assuming this is the rest of your code? and you have it in the html like this: If I was trying to clear the textarea I would put the text area into a self submitting form and have a php condition to check for a $_POST['reset'] value then reset the value of $text to "" before the form is rendered again... make sense? ;o)
CESIL Posted September 16, 2010 Report Posted September 16, 2010 (edited) This javascript will do what I think you want... <br /> function resetAll(){<br /> for($y=1;$y<4;$y++){<br /> document.getElementById("mon"+$y).value="";<br /> }<br /> }<br /> </pre><form action="" method="get" id="aa"> </for If you need to clear a textarea then use .innerText instead of .value on line 4 of the script Edited September 16, 2010 by CESIL Added code for textarea
SteveBentley Posted September 16, 2010 Report Posted September 16, 2010 if this issue is that $i is dynamic and could be any number, you might have to write the javascript to do the clear with PHP
powdarrmonkey Posted September 16, 2010 Report Posted September 16, 2010 I'm assuming this is the rest of your code? That would be "guessing". If I was trying to clear the textarea I would put the text area into a self submitting form and have a php condition to check for a $_POST['reset'] value then reset the value of $text to "" before the form is rendered again... make sense? ;o) Self-submit and spend time and resources invoking PHP? WTF? This is the user agent's responsibility, and the correct solution is a reset button. This javascript will do what I think you want... Similarly, Javascript is costly overkill. The type is "reset", not "button".
localzuk Posted September 16, 2010 Report Posted September 16, 2010 Hi Guys, I havce tried this and it does not work. I added a reset button, but on the page it doesn't do a thing! Regards - Stuart We need more code. Where on the page are you putting the button? There is no reason, even in a php generated html form, for a reset button not to work - emptying fields is what it is designed to do.
CESIL Posted September 16, 2010 Report Posted September 16, 2010 Similarly, Javascript is costly overkill. The type is "reset", not "button". I thought the OP wanted to clear specific fields...the javascript allows that more easily than a reset button which I believe resets all form elements to their default value. I was using a "button" type because I did not want the "reset" button for this use! BTW where do you keep your high horse when you get down off it?
pkkelly Posted November 12, 2010 Report Posted November 12, 2010 WTF? I'm hardly ever in this forum, and don't think I'll come back if this is the kind of attitude that I'm going to get.
localzuk Posted November 12, 2010 Report Posted November 12, 2010 I'm hardly ever in this forum, and don't think I'll come back if this is the kind of attitude that I'm going to get. You have been presented with a variety of options, all of which should work. Did any of them work? Why doesn't a simple reset button work?
powdarrmonkey Posted November 12, 2010 Report Posted November 12, 2010 I thought the OP wanted to clear specific fields...the javascript allows that more easily than a reset button which I believe resets all form elements to their default value. I was using a "button" type because I did not want the "reset" button for this use! BTW where do you keep your high horse when you get down off it? In the paddock next to my stupidity radar. I'm hardly ever in this forum, and don't think I'll come back if this is the kind of attitude that I'm going to get. No personal offence intended. But, really, your solution was very WTF over-engineering.
pkkelly Posted November 12, 2010 Report Posted November 12, 2010 no personal offence intended? lol... what do you expect when you comment someones post with "WTF?" ?!?! anyway... lets not hijack @01hanstu post... btw, did you ever sort this?
powdarrmonkey Posted November 12, 2010 Report Posted November 12, 2010 no personal offence intended? lol... what do you expect when you comment someones post with "WTF?" ?!?! Maybe if you didn't take it out of context you'd realise that your solution is stupid, not you. anyway... lets not hijack @01hanstu post... btw, did you ever sort this? As he hasn't been back since asking it...
CESIL Posted November 12, 2010 Report Posted November 12, 2010 As he hasn't been back since asking it... ...then perhaps one of us helped him...it would be funny if one of our 'stupid' suggestions worked...
webman Posted November 12, 2010 Report Posted November 12, 2010 Sometimes stupid suggestions do actually work, but that doesn't mean they're the right or best way to go about doing something.
CESIL Posted November 12, 2010 Report Posted November 12, 2010 Sometimes stupid suggestions do actually work ...which would make it a solution then?
sparkeh Posted November 12, 2010 Report Posted November 12, 2010 ...which would make it a solution then? Buying a tank to drive your kids to school is a solution. A stupid one, but a solution nonetheless.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now