S
SamuelXiao
I am a newbie in javascript. I have encountered a problem in the
following code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Blog Post</title>
<script type="text/javascript">
/*<![CDATA[ */
function validate_form(){
valid = true;
if(document.form1.author.value=""){
alert("Please fill in the 'Your name' box");
valid=false;
}
if(document.form1.content.value=""){
alert("Please fill in the 'Blog Content' box");
valid=false;
}
return valid;
}
/*]]>*/
</script>
</head>
<body>
<p>Create Blog</p>
<form name="form1" method="get" action="createPost.py"
onsubmit="return validate_form();">
<p><label for="author">Your Name:
<input type="text" size="30" name="author" id="author"/>
</label>
</p>
<p>Your Blog Content:<br />
<textarea rows="10" cols="45" name="content" id="content">Please
write your
blog here
</textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
<input name="Reset" type="reset" id="Reset" value="Reset" />
</p>
</form>
</body>
</html>
The javascript code is to validate a form. However, it is not work.
I think the problem is with xhtml? Or I miss something? I just want
to check whether the input or textarea is empty, if it is, the script
alert the user to input his information. And how can I set focus on
the input or textarea? I try document.form1.textarea.focus(); but it
is also not work. Any help would be appreciated. Thanks.
following code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Blog Post</title>
<script type="text/javascript">
/*<![CDATA[ */
function validate_form(){
valid = true;
if(document.form1.author.value=""){
alert("Please fill in the 'Your name' box");
valid=false;
}
if(document.form1.content.value=""){
alert("Please fill in the 'Blog Content' box");
valid=false;
}
return valid;
}
/*]]>*/
</script>
</head>
<body>
<p>Create Blog</p>
<form name="form1" method="get" action="createPost.py"
onsubmit="return validate_form();">
<p><label for="author">Your Name:
<input type="text" size="30" name="author" id="author"/>
</label>
</p>
<p>Your Blog Content:<br />
<textarea rows="10" cols="45" name="content" id="content">Please
write your
blog here
</textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
<input name="Reset" type="reset" id="Reset" value="Reset" />
</p>
</form>
</body>
</html>
The javascript code is to validate a form. However, it is not work.
I think the problem is with xhtml? Or I miss something? I just want
to check whether the input or textarea is empty, if it is, the script
alert the user to input his information. And how can I set focus on
the input or textarea? I try document.form1.textarea.focus(); but it
is also not work. Any help would be appreciated. Thanks.