Hi, Firstly, im a newbie to web developement, so please accept my apologies for my basic questions.
I have the following HTML
<head>
<link rel="stylesheet type" type="text/css" href="/My First Website/Inc/CSS/mycss.css"
<script type="text/javascript" src="/My First Website/Inc/JavaScript/Form.js"> </script><meta charset="utf-8"
<div> <form method="post" form name="HomePageForm">
First Name : <input type="text" name="firstname"/><br />
Surname : <input type="text" name="surname" /><br />
Password : <input type="password"name="pwd" /><br />
<input type ="submit" value = "Submit" /></div>
</head>
I have highlihted in Bold, the query i Have.
I dont know how to reference the form 'HomePageForm' in my javascript file.
I beleive i have referenced it OK in the HTML file, but i want to do some basic validation such as if the firstname and surname are blank then show a messagebox...
but im struggling on how to acheive this in the js file.
----------------------------------------------------------------------------------------------
WYSIWYG editors will never beat my hand written code!!!! Learn to do it in notepad and learn how to actually control your website! Current Project http://www.jmcanineservices.com
Hi, Firstly, im a newbie to web developement, so please accept my apologies for my basic questions.
I have the following HTML
<head>
<link rel="stylesheet type" type="text/css" href="/My First Website/Inc/CSS/mycss.css"
<script type="text/javascript" src="/My First Website/Inc/JavaScript/Form.js"> </script><meta charset="utf-8"
<div> <form method="post" form name="HomePageForm">
First Name : <input type="text" name="firstname"/><br />
Surname : <input type="text" name="surname" /><br />
Password : <input type="password"name="pwd" /><br />
<input type ="submit" value = "Submit" /></div>
</head>
I have highlihted in Bold, the query i Have.
I dont know how to reference the form 'HomePageForm' in my javascript file.
I beleive i have referenced it OK in the HTML file, but i want to do some basic validation such as if the firstname and surname are blank then show a messagebox...
but im struggling on how to acheive this in the js file.
Can someone please help.
Thanks
Hi Boss
Place onclick="validateNames();" in Submit Button like below
<input type="password"name="pwd" /><br />
<input type ="submit" value = "Submit" onclick="validateNames();" />
in Js File , place the below function
function validateNames(){
if(document.HomePageForm.firstname=="" || document.HomePageForm.surname==""){
alert("firstName and surName should not be empty");
return false;
}
return true;
}
And also, I did not find the action attribute in your form Tag..which is mandatory. Please read about the action tag and place it accordingly.
Bookmarks