+ 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.
39 ответов
+ 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(){
};
+ 13
Html:
<button onclick="hi()">click</button>
JavaScript:
function hi() {
alert("hello world");
}
+ 11
Tanisha Gupta I am Namit Jain and not Namita Jain😑
The code is working perfectly 👍
Do you want something else?
+ 8
alert("alert message");
+ 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?
+ 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.
+ 7
Divya Mohan please don't send the whole solution
+ 6
Simba semi-colon doesn't matter I think🤔
+ 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.
+ 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");
}
+ 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");
};
};
+ 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.
+ 4
Divya Mohan I'm a girl not a boy bro. I'm just correcting uh.
+ 3
This will help you!
https://code.sololearn.com/WMP3Ptl3mYqB/?ref=app
+ 3
You can understand it more easily
https://code.sololearn.com/WMP3Ptl3mYqB/?ref=app
+ 3
Namit Jain Thanks 🤗 🤗
you guys can now check my code .
it is working perfectly because of you guys .
thanks to everyone.
+ 3
Tanisha Gupta you can change the input types!
tel date number
+ 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 :)
+ 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.