Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi CG how you r doing? am editing a old site built in asp. it is just a html page... so and form is like this
<form action="viewrecords.asp" method="post">
Date<input type="text" readonly="readonly" name="theDate" id="Date"/> 
<input type="button" value="Date"
onclick="displayCalendar(document.forms[0].theDate,'yyyy/mm/dd',this)"/>

java script if return true does not submits the form
function chkvalid()
{
 if(document.getElementById("Date").value=="" &&  document.getElementById("ddlModel").value==0)
 {
  alert("he");
  return false;
 }
 else
 {
  return true;
 }
}

<input value="Show" onclick="return chkvalid();" type="button" />
Posted
Updated 14-Feb-10 15:52pm
v3

Have you traced the code ? looked at the source ? What makes you think that your elements have the names you used ? If it's because you gave them those names in ASP.NET, then the client side id is in the ClientID property.

However, from what you're saying, I think the main issue is that you expect a button to submit your form, for reasons that I don't understand. Why do you expect this button to submit the form ? Pls edit your post to add this info.
 
Share this answer
 
XML
<html>
<head>
<script type="text/javascript">
function chkvalid()
{
if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value=="0")
{
alert("He");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="viewrecords.asp" method="post">
<input type="submit" onclick="return chkvalid()" value="Show" />
<input type="text"  id="Date" />
<input type="text"  id="ddlModel" />
</form>
</body>
</html>


This should do the trick.
 
Share this answer
 
v3
Couple of simple options;

  1. Change the type from button to submit
  2. or place document.myform.submit(); before return true; (change myForm to the name of the form)


-- EDIT --
Do option 1. change the type of the button from button to submit and it works.
XML
<html>
<head>
<title>Title</title>
<script type="text/javascript">
function chkvalid()
{
  if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value=="0")
  {
    alert("he");
    return false;
  }
  else
  {
    return true;
  }
}
</script>
</head>
<body>
<form action="viewrecords.asp" method="post">
Date<input type="text" id='Date'/><BR>
<input type="text" id='ddlModel'/><BR>
<input value="Show" onclick="return chkvalid();" type="submit" />
</form>
</body>
</html>
 
Share this answer
 
v3
you can put an onsubmit event in form:

XML
<html>
<head>
<script type="text/javascript">
function chkvalid(){
if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value=="0"){
    alert("He");
    return false;
}
else{
    return true;
}
}
</script>
</head>
<body>
<form action="viewrecords.asp" method="post" onsubmit="return chkvalid()">
<input type="submit" value="Show" />
<input type="text"  id="Date" />
<input type="text"  id="ddlModel" value="0"/>
</form>
</body>
</html>
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900