Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

The html code for the creation of form:


<form action="processUpdate.php" method="post" enctype="multipart/form-data" name="update" class="paparan">
The html code for the button:


<input name="reset" onclick="resetfData()" type="button" form="update" value="Semula" class="good">
Javascript function for resetting of form data:


function resetfData(){
	
	document.getElementsByClassName('paparan').reset();
	
}

When the reset button is clicked,nothing happens.

If i replace the document.getElementsByClassName with:


function resetfData(){
	
	alert("hello");
	
}


It works,the hello alert box came up.However document.write and console.log doesnt work.

Ive also tried using this.form.reset();

Ive got a similar problem while i was doing clearing the form(note the difference between clear and reset) using http://javascript-coder.com/javascript-form/javascript-reset-form.phtml,but i fixed it myself like this:-

function clearfData(){
	
	document.getElementById('name').value = "";
	document.getElementById('class').value = "";
	document.getElementById('address').value = "";
	document.getElementById('gender').value = "";
	document.getElementById('tel').value = "";
	document.getElementById('jawatan').value = "";
	document.getElementById('care').value = "";
	document.getElementById('telCare').value = "";
	
}

but now the similar thing is happening to resetting the form.I think my main problem is that i cannot get the form object using javascript.How do i fix this?Any idea?

Ive tried solving it myself the whole day,but to no avail,thats why i decided to ask it here.

  • Author

Yup,ive tried that,it works,but there are two problem:-

1)I want to alert the user that the form has been cleared when the button is pressed.

2)When i click clear,then click reset,the form is cleared and the default value is restored,but when i click return or submit the form,it says this field is required.Only if i press clear and reset again or reload the page,the return and submit button continues to work again.

I have alternative to solve this problem,but instead of using alternative and running away from my problems,i prefer finding out what's wrong.

Btw,ive also just tried using window.location.reload(),but nah,it doesnt work.

Edited by Cheah Hsun Teik

Once again, if you can post a link to the form we can see the problem and use diagnostic tools to find a solution.

  • Author

Everything is on my localhost.I don't think it's public,so I can't send the link.Can you teach me how to publish my website for free???

Is it really not possible to find the problem without looking at the publish website?

Can't you just look at all the information I gave and guess what is the problem??

Or maybe you can teach me how to use the diagnostic tool you are talking about so I can do it myself.

Edited by Cheah Hsun Teik

32 minutes ago, Cheah Hsun Teik said:

Is it really not possible to find the problem without looking at the publish website?

Thing is you've only posted a handful of snips without context. Being able to see the complete page would mean we could read the lot and see where the problem could be.

If it's local hosted then make us a fiddle of the components to look at, somewhere like JSFiddle. Then link the fiddle here so we can see the html, css and js separately. We can then adjust the fiddle to see where the problem is and hopefully give you an answer rather than a guess.

Yes the JSFiddle doesn't support PHP, although there is PHPFiddle the issue is with JS. I've cleaned up the example to remove the PHP at https://jsfiddle.net/jm4sbq7d/.

7 hours ago, Cheah Hsun Teik said:

1) I want to alert the user that the form has been cleared when the button is pressed.

Do you want the warning before or after the form is cleared?

7 hours ago, Cheah Hsun Teik said:

2) When i click clear, then click reset, the form is cleared and the default value is restored, but when i click return or submit the form, it says this field is required. Only if i press clear and reset again or reload the page, the return and submit button continues to work again.

I'm a little confused here. By the sounds of things when you click 'reset' you want to restore the initial data in the form like when the page is first loaded? So clicking clear, think "whoops" and want it all back to how it was when the page first loaded?

  • Author
11 minutes ago, BrowserBugs said:

Do you want the warning before or after the form is cleared?

Nevermind,already know how to do this....

 

15 minutes ago, BrowserBugs said:

I'm a little confused here. By the sounds of things when you click 'reset' you want to restore the initial data in the form like when the page is first loaded? So clicking clear, think "whoops" and want it all back to how it was when the page first loaded?

What i meant is when i clicked clear,then i click reset,then i click submit,it should submit the form,but instead it gives "this field is required message".Ive made sure ive filled in all the field of the form,including the image,so why isnt it submitting.

10 minutes ago, Cheah Hsun Teik said:

What do you mean by this???

Which issue??

You're using JavaScript to clear, JavaScript to reset, why would the problem not be in the JavaScript? If there's no issues with the page then what's the freaking problem????? I give up mate, someone else might have the patience.

1 hour ago, Cheah Hsun Teik said:

What i meant is when i clicked clear,then i click reset,then i click submit,it should submit the form,but instead it gives "this field is required message".Ive made sure ive filled in all the field of the form,including the image,so why isnt it submitting.

That's because you've cleared the form fields! Will try and slow this down for you. You have ...

<input name="name" id="name" type="text" required="required" form="update" value="James Brown">

... now you clear the data with clearfData(), part of which empties the name field via document.getElementById('name').value = ""; which makes ...

<input name="name" id="name" type="text" required="required" form="update" value="">

... now you click reset which triggers resetfData() nothing actually gets reset, it only produces an alert message, so outr for field is still ...

<input name="name" id="name" type="text" required="required" form="update" value="">

... and since that form field is "required" and it's value is empty of course you'll get that field is required message.

If this form is for updating a profile then it should never have a clear option, why on earth would anyone clear everything when they just wanted to change one thing?

Edited by BrowserBugs

  • Author

Ohh,ok,I understand that,but when I click reset,the value actually came back,I can see the values showing at the form,its only not submitting when I click submit.

 

Edited by Cheah Hsun Teik

  • Author
25 minutes ago, BrowserBugs said:

If this form is for updating a profile then it should never have a clear option, why on earth would anyone clear everything when they just wanted to change one thing?

Ok,I'll remove the clear,it actually makes sense,the user can also just delete the whole thing and recreate a new profile,if they want,instead of clearing. Thanks..

Just now, Cheah Hsun Teik said:

Ok,I'll remove the clear,it actually makes sense,the user can also just delete the whole thing and recreate a new profile,if they want,instead of clearing. Thanks..

Probably a better idea. For update forms I only give 1 button, update. Also nice to have a linked 'cancel' button back to their overview, essentially just a link but gives the impression they've aborted any changes etc.

  • Author

My javascript function that i defined is still not called when the button is clicked though,except alert().

i can actually just write the full code directly in the buttons onclick attribute,instead of using functions,it works,but i dont think thats a good idea.

My another problem is:-unlink() gives me a permission denied error when i want to delete my picture from  a folder.I know i need to enable or disable some permission thing,but what is it though.How do i fix it?

Edited by Cheah Hsun Teik

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.