+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
Coding Thread, PHP Help in Coding and Web Development; Hi, Wondering if someone can help! I need to be able to create a button on my page to clear ...
  1. #1
    01hanstu's Avatar
    Join Date
    Sep 2007
    Location
    Manchester
    Posts
    148
    Thank Post
    17
    Thanked 1 Time in 1 Post
    Rep Power
    0

    PHP Help


    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:
    PHP Code:
    <? $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

  2. #2

    EduTech's Avatar
    Join Date
    Aug 2007
    Location
    Reading
    Posts
    5,047
    Thank Post
    160
    Thanked 913 Times in 716 Posts
    Blog Entries
    3
    Rep Power
    271
    Does this help: Usability Tip: RESET Button and Forms

    James.

  3. #3
    01hanstu's Avatar
    Join Date
    Sep 2007
    Location
    Manchester
    Posts
    148
    Thank Post
    17
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Hi,
    Unfortunatly this doesnt work. The fields are generated by php (through the loop).
    Regards,
    - Stuart

  4. #4

    EduTech's Avatar
    Join Date
    Aug 2007
    Location
    Reading
    Posts
    5,047
    Thank Post
    160
    Thanked 913 Times in 716 Posts
    Blog Entries
    3
    Rep Power
    271
    oh right! dunno then I'm dense when it comes to PHP etc. unless it's basic Sorry

  5. #5
    01hanstu's Avatar
    Join Date
    Sep 2007
    Location
    Manchester
    Posts
    148
    Thank Post
    17
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Yeah - me too. Pickup the useful stuff ... ditched the rest

  6. #6

    EduTech's Avatar
    Join Date
    Aug 2007
    Location
    Reading
    Posts
    5,047
    Thank Post
    160
    Thanked 913 Times in 716 Posts
    Blog Entries
    3
    Rep Power
    271
    yeah the pro's will be here soon enough! lol

  7. #7

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Quote Originally Posted by 01hanstu View Post
    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:
    PHP Code:
    <? $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.

  8. #8

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,660
    Thank Post
    516
    Thanked 2,444 Times in 1,892 Posts
    Blog Entries
    24
    Rep Power
    831
    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.

  9. #9
    01hanstu's Avatar
    Join Date
    Sep 2007
    Location
    Manchester
    Posts
    148
    Thank Post
    17
    Thanked 1 Time in 1 Post
    Rep Power
    0
    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

  10. #10

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,660
    Thank Post
    516
    Thanked 2,444 Times in 1,892 Posts
    Blog Entries
    24
    Rep Power
    831
    Quote Originally Posted by 01hanstu View Post
    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?

  11. #11

    Join Date
    Mar 2010
    Location
    Dumfries
    Posts
    4
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0
    PHP Code:
    <? 
    $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:

    HTML Code:
    <textarea name="text1" id="text1"><php echo $text; ?> </textarea>
    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)

  12. #12

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    This javascript will do what I think you want...

    Code:
    <script>
    function resetAll(){
    	for($y=1;$y<4;$y++){
    		document.getElementById("mon"+$y).value="";
    	}
    }
    </script>
    </head>
    
    <body>
    <form action="" method="get" id="aa">
    <p><input id="mon1" type="text"></p>
    <p><input id="mon2" type="text"></p>
    <p><input id="mon3" type="text"></p>
    <p><input id="reset" type="button" onclick="resetAll()" value="Reset">
    </p>
    </form>
    If you need to clear a textarea then use .innerText instead of .value on line 4 of the script
    Last edited by CESIL; 16th September 2010 at 01:07 PM. Reason: Added code for textarea

  13. #13
    SteveBentley's Avatar
    Join Date
    Jun 2007
    Location
    Yorkshire
    Posts
    1,432
    Thank Post
    120
    Thanked 263 Times in 189 Posts
    Rep Power
    72
    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

  14. #14

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Quote Originally Posted by pkkelly View Post

    I'm assuming this is the rest of your code?
    That would be "guessing".

    Quote Originally Posted by pkkelly View Post
    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.

    Quote Originally Posted by CESIL View Post
    This javascript will do what I think you want...

    [CODE]
    <p><input id="reset" type="button" onclick="resetAll()" value="Reset">
    Similarly, Javascript is costly overkill. The type is "reset", not "button".

  15. #15

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,660
    Thank Post
    516
    Thanked 2,444 Times in 1,892 Posts
    Blog Entries
    24
    Rep Power
    831
    Quote Originally Posted by 01hanstu View Post
    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.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. PHP ?
    By mac_shinobi in forum Web Development
    Replies: 31
    Last Post: 15th January 2010, 06:58 PM
  2. PHP
    By faza in forum How do you do....it?
    Replies: 4
    Last Post: 3rd December 2008, 01:56 PM
  3. PHP ID
    By Jackd in forum Coding
    Replies: 4
    Last Post: 30th November 2008, 01:08 PM
  4. PHP Help!
    By Cravon in forum Coding
    Replies: 2
    Last Post: 20th November 2007, 05:05 PM
  5. Help with PHP
    By Gatt in forum Web Development
    Replies: 1
    Last Post: 14th November 2006, 09:01 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •