June 26, 20197 yr 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.
June 26, 20197 yr If you're trying to clear fields in a form have you tried a normal reset input with no JS? <input type="reset" value="Reset">
June 27, 20197 yr 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 June 27, 20197 yr by Cheah Hsun Teik
June 27, 20197 yr Once again, if you can post a link to the form we can see the problem and use diagnostic tools to find a solution.
June 27, 20197 yr 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 June 27, 20197 yr by Cheah Hsun Teik
June 27, 20197 yr 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.
June 27, 20197 yr Author Which part of the code do I need to post? Posting the whole thing is too long,but ill try to post it anyway,in a few minutes...
June 27, 20197 yr Author Heres the code that doesnt work: https://jsfiddle.net/j3rkufm2/ This is the alternative i tried that works: https://jsfiddle.net/17xd9utm/1/ jsfiddle cannot understand php.The header's background colour is also not displaying when run,so it may look a bit weird. Hope you all can help me... Edited June 27, 20197 yr by Cheah Hsun Teik
June 27, 20197 yr 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?
June 27, 20197 yr 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.
June 27, 20197 yr Author 23 minutes ago, BrowserBugs said: the issue is with JS. What do you mean by this??? Which issue?? Edited June 27, 20197 yr by Cheah Hsun Teik
June 27, 20197 yr 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.
June 27, 20197 yr Author Ohh...I'm was just confused what issue you mean,beacause there's many issues,maybe try including the subject next time,so that I'll understand...
June 27, 20197 yr 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 June 27, 20197 yr by BrowserBugs
June 27, 20197 yr 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 June 27, 20197 yr by Cheah Hsun Teik
June 27, 20197 yr 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..
June 27, 20197 yr 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.
June 27, 20197 yr 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 June 27, 20197 yr by Cheah Hsun Teik
Create an account or sign in to comment