Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted
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?

  • 2 weeks later...
Posted

 
$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)

Posted (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 by CESIL
Added code for textarea
Posted

 

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".

Posted
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.

Posted
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?

  • 1 month later...
Posted
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?

Posted
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.

Posted

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?

Posted
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...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...