+ 9

How to add a alert msg after completion of form? You guys can check my ansr and please let me know that what can i do.

https://code.sololearn.com/WHGwX61Fs4HU/?ref=app

29th Jul 2020, 9:30 AM
Tanisha Gupta
Tanisha Gupta - avatar
39 Réponses
+ 8
Tanisha Gupta window.onload function runs js only after document is fully loaded ,basically it prevents js to be executed before Dom is fully loaded otherwise that would return null on accessing the elements like form that don't exist yet,you Don't need to write code inside that function if you are using script just before body tag, So document.querySelector("form") selects the form tag ,and form.onsubmit listens for submit event on form ,so when form is valid it executes whatever is passed inside the following function =()=>{ }; The above is es6 syntax for writing function in more readable and shorter way ,which is basically function(){ };
29th Jul 2020, 11:04 AM
Abhay
Abhay - avatar
+ 13
Html: <button onclick="hi()">click</button> JavaScript: function hi() { alert("hello world"); }
29th Jul 2020, 9:33 AM
Namit Jain
Namit Jain - avatar
+ 11
Tanisha Gupta I am Namit Jain and not Namita Jain😑 The code is working perfectly 👍 Do you want something else?
29th Jul 2020, 10:00 AM
Namit Jain
Namit Jain - avatar
+ 8
alert("alert message");
29th Jul 2020, 9:42 AM
Samira
Samira - avatar
+ 7
If it's a "post" form then that's something you have to handle from backend, could you explain where this form data is going?
29th Jul 2020, 9:38 AM
Bhavya
Bhavya - avatar
29th Jul 2020, 10:02 AM
Bhavya
Bhavya - avatar
+ 7
Namit Jain I'm sorry Namit Jain.I was in a hurry and I mistakenly wrote the wrong name. I hope you don't mind this thing.
29th Jul 2020, 10:10 AM
Tanisha Gupta
Tanisha Gupta - avatar
+ 7
Divya Mohan please don't send the whole solution
29th Jul 2020, 11:04 AM
Namit Jain
Namit Jain - avatar
+ 6
Simba semi-colon doesn't matter I think🤔
29th Jul 2020, 10:01 AM
Namit Jain
Namit Jain - avatar
+ 6
Thanks guys but still there is an issue if we add this alert msg outside the form it works else it is not working and if add "required" to some data then our submission will not working acc that it will directly submit the form with showing them any alert msg regarding required details.You can recheck my code I have made that changes and it will be easy for uh to spot my query.
29th Jul 2020, 10:05 AM
Tanisha Gupta
Tanisha Gupta - avatar
+ 6
You can try this,listen for submit event on form, when all the required details are filled alert, "thanks for registration", var form=document.querySelector("form") form.onsubmit=()=>{ alert("thanks for registration"); }
29th Jul 2020, 10:23 AM
Abhay
Abhay - avatar
+ 5
Tanisha Gupta remove that function from js file ,and add this code window.onload=function(){ var form=document.querySelector("form"); form.onsubmit=()=>{ alert("Thks for registration"); }; };
29th Jul 2020, 10:39 AM
Abhay
Abhay - avatar
+ 4
In your form tag simply add Onsubmit="alert('thanks for registration')" as an attribute and value. Write single and double quotes are they are.
29th Jul 2020, 10:31 AM
Divya Mohan
Divya Mohan - avatar
+ 4
Divya Mohan I'm a girl not a boy bro. I'm just correcting uh.
29th Jul 2020, 10:50 AM
Tanisha Gupta
Tanisha Gupta - avatar
29th Jul 2020, 10:42 AM
Namit Jain
Namit Jain - avatar
+ 3
You can understand it more easily https://code.sololearn.com/WMP3Ptl3mYqB/?ref=app
29th Jul 2020, 10:50 AM
Namit Jain
Namit Jain - avatar
+ 3
Namit Jain Thanks 🤗 🤗 you guys can now check my code . it is working perfectly because of you guys . thanks to everyone.
29th Jul 2020, 10:51 AM
Tanisha Gupta
Tanisha Gupta - avatar
+ 3
Tanisha Gupta you can change the input types! tel date number
29th Jul 2020, 11:06 AM
Namit Jain
Namit Jain - avatar
+ 3
HI! Sis Tanisha Gupta You can add maxlength=10 in td tag that contains about phone number. As : <td><input type ="number" name="" maxlength="10" /></td> So,that ur code will be great enough to type phone number of 10 digits only. And I know that I didn't gave u the answer for ur question.Bcz,I'm a beginner to Js and started learning it just 2-3 days back. Correct me if I'm wrong. HAPPY CODING :)
29th Jul 2020, 5:29 PM
Vishnu_kishore@473
Vishnu_kishore@473 - avatar
+ 3
Vishnu_kishore@473 Thanks for your suggestion but it will not work if we use type=number ,.But if we use type=text and we'll put maxlength attribute then it will work. Hope it will help you. But yes u can use <input type="tel" maxlength="10" /> or u can check my code for more info.
29th Jul 2020, 5:40 PM
Tanisha Gupta
Tanisha Gupta - avatar