Hi All,
I have the following code with two Javascript functions. When
I submit the form, it does not navigate to the next page. I tried
lot of alternatives but nothing seems to work. Can anyone kindly
suggest what is wrong with the code below:
index.cfm
<!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>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script language="javascript">
function validate_form()
{
if(document.myform.lastname.value == '')
alert('Please enter a value for Lastname');
return false;
}
function saySomething(arg)
{
document.myform.firstname.value = arg;
if(validate_form()){
document.myform.submit();
return false;
}
}
</script>
<body>
<form method="post" action="index1.cfm" name="myform">
First Name:<input type="text" name="firstname"
id="firstname" value=""/><br />
Last Name:<input type="text" name="lastname" id="lastname"
value=""/>
<a href="javascript:saySomething('me');">Click here
for me</a>
<a href="javascript:saySomething('all');">Click here
for all</a>
</form>
</body>
</html>
index1.cfm
<cfoutput>Hello</cfoutput>
<!--- make sure firstname is defined and has a value that
isn't an empty string, if not, use "me" --->
<cfif isdefined("form.firstname") and Trim(form.firstname)
neq "">
<cfset myvariable = #form.firstname#>
<cfelse>
<cfset myvariable = "me" />
</cfif>
<cfoutput>#myvariable#</cfoutput><br />
<cfif form.firstname eq 'me'>
<cfoutput>This is me</cfoutput>
<cfelse>
This is not me.This is all
</cfif>
<cfif isdefined("form.lastname") and Trim(form.lastname)
neq "">
<cfoutput>#form.lastname#</cfoutput>
</cfif>