HTTP Status 400 – Bad Request - spring-mvc

Hi i am trying to select category while adding new category.Category details get from DB and I am trying to fetch it's PK to product command by using <form:select> tag.
But it shows following error.
error
HTTP Status 400 – Bad Request
Type Status Report
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
My Controller
#RequestMapping(value="productlist/addproduct" , method=RequestMethod.POST)
public String addProdt( #ModelAttribute ("prdt") Product p)
{
pd.addProduct(p);
MultipartFile prodImage=p.getImage();
if(!prodImage.isEmpty()){
Path paths=Paths.get("C:/Users/Dont open/Documents/Eclipse/ClickBuy/src/main/webapp/resources/Images/"+ p.getId()+".png");
try
{
prodImage.transferTo(new File(paths.toString()));
} catch (IllegalStateException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
return "redirect:/allProduct";
}
Jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# include file="header.jsp"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# page isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# page isELIgnored="false" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#mfg" ).datepicker();
} );
</script>
</head>
<body>
<br>
<h2 align="center">PRODUCT FORM</h2><hr>
<div class="col-md-2 "></div>
<div align="center"><div class="container"><div class="col-md-8 ">
<form:form method="POST" action="productlist/addproduct" commandName="prdt" enctype="multipart/form-data">
<table class="table table-hover">
<tr>
<td> <form:label path="product_Name"> Enter Product Name</form:label></td>
<td><form:input type="text" path="product_Name" class="form-control"/></td>
</tr>
<tr>
<td> <form:label path="descripction"> Enter Product Descripction</form:label></td>
<td><form:input type="text" path="descripction" class="form-control"/></td>
</tr>
<tr>
<td> <form:label path="category"> Enter Product Category</form:label></td>
<td>
<form:select path="category">
<c:forEach var="x" items="${catg}">
<form:option value="${x.category_id}" label="${x.category_name}" /></c:forEach>
</form:select>
</td>
</tr>
<tr>
<td> <form:label path="price"> Enter Product Price</form:label></td>
<td><form:input type="text" path="price" placeholder=" Enter Product Price" class="form-control"/>
</td></tr>
<tr>
<td> <form:label path="mfg_Date"> Enter Manufacture Date</form:label></td>
<td><form:input type="text" id="mfg" path="mfg_Date" class="form-control"/></td>
</tr>
<tr>
<td> <label> Choose Image</label></td>
<td><form:input type="file" path="image" class="form-control"/></td>
</tr>
</table>
<input type="submit" class="btn btn-primary btn-block" value="Add" class="form-control"/>
</form:form>
</div></div></div></body>
</html>
Thanks in advance!!

This error has nothing to do with <form:select> tag
Still There are few things missing in your code which is resulting this error.
In JSP you are trying to upload file along with form data so you need to have multipartResolver bean defined in spring context from common-fileupload.jar
MultipartResolver Spring
Controller method should be changed like this
#RequestMapping(value="/productlist/addproduct" , method= RequestMethod.POST,consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ModelAndView addProdt(#ModelAttribute("prdt") Product p,BindingResult bindingResult)

This is an old question but In case anyone else experiences the same issue then look how I solved it.
The problem has nothing to do with the post method that was provide. It is thrown by the next page that you are redirecting to ("redirect:/allProduct"). Your ORM could not successfully map the database result to individual objects, this could be caused by not specifying a primary key or having keys that evaluate to null. So visit your database and fix it, make sure you have everything correct in the end.

Error
HTTP Status 400 – Bad Request depctive, malfunction
Type Status Report
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested in logs
I have got the same error while redirecting from one handler to another, my handler was handling request but it couldn't redirected to another Page.
return"redirect:/employeeReport";
I tried all methods but that couldn't solve my issue.
Then I just found that there was sequence mismatch in Entity property and form Property. Just matched all my Entity property and cleaned my project issue resolved.
Advice: Map all fields of your Entity class properly with your form, clean project and run again. Even if there is no issue in mapping of Entity's field this error comes then simply clean project and rerun might work.

Related

Spring MVC #ModelAttribute in method parameter not binding data with java object

HTTP Status 400 – Bad Request Type Status Report
Description The server cannot or will not process the request due to
something that is perceived to be a client error (e.g., malformed
request syntax, invalid request message framing, or deceptive request
routing).
I am new in Spring MVC and learning about #modelattribute annotation and getting above error.Everything else works fine without modelattribute annotaion. I even tried using #RequestParam instead of #modelattribute and everthing worked fine. But I am not able to understand what is wrong with the code below. Please can anyone help?
AdmissionController.java
package Demo.SpringAnnotation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class AdmissionController {
#RequestMapping(value="/welcome",method=RequestMethod.GET)
public ModelAndView formLoad() {
ModelAndView mav = new ModelAndView("AdmssionForm");
return mav;
}
#ModelAttribute
public void commonHeaders(Model model1) {
model1.addAttribute("headers", "New College of Engineering");
}
#RequestMapping(value="/admissionsucess",method=RequestMethod.POST)
public ModelAndView submitForm(#ModelAttribute("student1") Student student1) {
ModelAndView mav=new ModelAndView("AmissionSucess");
return mav;
}
}
AdmissionForm.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Admission Form</title>
</head>
<body>
<h2>${headers }</h2>
<form action="/SpringAnnotation/admissionsucess" method="post">
<table>
<tr>
<td>Name :</td>
<td><input type="text" name="studentName"></td>
</tr>
<tr>
<td>Hobbies:</td>
<td><input type="text" name="studentHobby"></td>
</tr>
<tr>
<td>Mobile:</td>
<td><input type="text" name="studentMobile"></td>
</tr>
<tr>
<td>Date Of birth:</td>
<td><input type="text" name="studentHobby"></td>
</tr>
<tr>
<td>Student Skills:</td>
<td><select name="studentSkills" multiple >
<option value="Java Core">Java Core</option>
<option value="Spring Core">Spring Core</option>
<option value="Spring MVC">Spring MVC</option>
</select></td>
</tr>
</table>
<button type="submit">Submit</button>
</form>
</body>
</html>
AdmissionSuccess.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Admission Sucess</title>
</head>
<body>
<h2>${headers }</h1>
<h4>Congratulation ${student1.studentName }, Your details are below</h4>
<table>
<tr>
<td>Name:</td>
<td>${student1.studentName}</td>
</tr>
<tr>
<td>Hobbies:</td>
<td>${student1.studentHobby}</td>
</tr>
<tr>
<td>Mobile:</td>
<td>${student1.studentMobile}</td>
</tr>
<tr>
<td>Date Of Birth:</td>
<td>${student1.studentDOB}</td>
</tr>
<tr>
<td>Name:</td>
<td>${student1.studentSkills}</td>
</tr>
</table>
</body>
</html>
You may need to annotate your class not as #Controller but as #ControllerAdvice. A useful page providing an example of the use of #ModelAttribute-- http://www.baeldung.com/spring-mvc-and-the-modelattribute-annotation --comments:
It is also important that you annotate the respective class as
#ControllerAdvice. Thus, you can add values in Model which will be
identified as global. This actually means that for every request a
default value exists, for every method in the response part.
Perhaps you are not adding all attributes in your Student class? In any event, perhaps a default object for Student is not available since #ControllerAdvice is not being used. I hope this helps. But regardless, more useful documentation on the subject can be found on that page I referenced above.

Spring form validation: unable to print errors in jsp

I am working on spring mvc application, there I have a form where a user can change his password. I am validating this form by using default spring form validation (see validator code below).
JSP Page:
<%# taglib uri="http://www.springframework.strong textorg/tags/form" prefix="spring"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Change password </title>
</head>
<body>
<%#include file="index.jsp" %>
<div class="row">
<div class="container" style=" background-color: #F9FFED; ">
<div>
<h4><label>Change password:</label></h4>
</div>
<div class="col-md-12" >
<spring:form commandName="ChangePassword" action="ChangePassword.do" method="post">
<table>
<tr>
<td><label for="current_pwd" >Current Password</label></td>
<td><spring:input path="current_pwd" type="text" class="form-control" placeholder="Name"/></td>
<td><spring:errors path="current_pwd" type="text" cssStyle="color: red;"></spring:errors></td>
</tr>
<tr>
<td>&nbsp</td>
</tr>
<tr>
<td><label for="newpassword" >New Password</label></td>
<td><spring:input path="newpassword" type="text" class="form-control" placeholder="Password"/></td>
<td><spring:errors path="newpassword" type="text" cssStyle="color: red;"></spring:errors></td>
</tr>
<tr>
<td>&nbsp</td>
</tr>
<tr>
<td><label for="confirmPassword" >Confirm Password</label></td>
<td><spring:input path="confirmPassword" type="text" class="form-control" placeholder="Password"/></td>
<td><spring:errors path="confirmPassword" type="text" cssStyle="color: red;"></spring:errors></td>
</tr>
<tr>
<td>&nbsp</td>
</tr>
<tr>
<td>
<button type="submit" class="btn btn-success"> SAVE </button>
Cancel
</td>
</tr>
</table>
</spring:form>
</div>
</div>
</div>
</body>
</html>
Controller get and post methods:
#RequestMapping(value="/ChangePassword",method=RequestMethod.GET)
public String changePassword(ChangePassword chPaswd,BindingResult result,ModelMap model){
chPaswd=new ChangePassword();
model.addAttribute("ChangePassword",chPaswd);
return "ChangePassword";
}
#RequestMapping(value="/ChangePassword",method=RequestMethod.POST)
public String changePasswordPost(ChangePassword chpwd,BindingResult result,ModelMap model,HttpSession session){
String message="";
changepwdValidator.validate(chpwd, result);
chpwd=new ChangePassword();
if(result.hasFieldErrors()){
System.out.println("Has errors");
model.addAttribute("ChangePassword",chpwd);
return "ChangePassword";
}else{
System.out.println("chnage pwd values :"+chpwd.getNewpassword()+","+"current pwd:"+chpwd.getCurrent_pwd());
try{
// some other operations
model.addAttribute("ChangePassword",chpwd);
}catch(Exception e){
message="Failed to process the request, please re-verify the values!";
model.addAttribute("message", message);
}
return "ChangePassword";
}
}
Validator class:
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import com.knot.pirautomation.models.ChangePassword;
public class ChangePasswordValidator implements Validator{
ChangePassword chngepwd;
public boolean supports(Class clazz) {
return ChangePassword.class.equals(clazz);
}
public void validate(Object target, Errors errors) {
if(target instanceof ChangePassword){
chngepwd=(ChangePassword) target;
System.out.println("----------");
System.out.println("Old pwd:"+chngepwd.getCurrent_pwd());
System.out.println("new pwd:"+chngepwd.getNewpassword());
System.out.println("confirm pwd:"+chngepwd.getConfirmPassword());
System.out.println("----------");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newpassword", "NewPassword.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "confirmPassword", "ConfirmPassword.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "current_pwd", "Oldpassword.required");
if( !(chngepwd.getNewpassword().equals(chngepwd.getConfirmPassword()))){
errors.rejectValue("newpassword", "NewPassword.match");
}
if((chngepwd.getNewpassword().length()<8)){
errors.rejectValue("newpassword", "NewPasswordlength.match" );
}
if((chngepwd.getConfirmPassword().length()<8)){
errors.rejectValue("confirmPassword", "ConfirmPasswordlength.match" );
}
String blackListChars = "!'=();<> \"";
char blackListArr[] = blackListChars.toCharArray();
for(int i=0;i<blackListArr.length;i++) {
if(chngepwd.getNewpassword().contains("" + blackListArr[i])) {
errors.rejectValue("newpassword","NewPassword.invalidChars");
break;
}
}
for(int i=0;i<blackListArr.length;i++) {
if(chngepwd.getConfirmPassword().contains("" + blackListArr[i])) {
errors.rejectValue("confirmPassword","ConfirmPassword.invalidChars");
break;
}
}
}
}
}
error.properties file:
Oldpassword.required= Old password is required
NewPassword.required= New password is required
ConfirmPassword.required= Confirm password should be required
NewPassword.match= Confirmation passwords should match
NewPasswordlength.match= New Password should be at least 8 characters
ConfirmPasswordlength.match= Confirm Password should be at least 8 characters
NewPassword.invalidChars=New Password has special characters which are not allowed
ConfirmPassword.invalidChars= Confirm Password has special characters which are not allowed
You can see that when the form has errors, I am returning control back to the same JSP.
My problem is that I am unable to trace the bug/error where my spring form validation is working fine, but when I am trying to display the errors which are defined in my properties file.
You should not explicitly invoke validator. Use this validation method instead:
#Valid #ModelAttribute("forName") FormName formName,
BindingResult bindingResult, Model model,
RedirectAttributes redirectAttributes, HttpSession session

Storing user input in classic asp

What i have to create is a form that i migrated out of access. I created the 4 asp pages. Now what they would like is to store the user input values some how until they hit the final page before writing to the SQL database. What is the easiest way to store this data until the final page for submission? I could try an array or maybe even java script?
You could use the session object - http://msdn.microsoft.com/en-us/library/ms525095(v=vs.90).aspx
As suggested in this other answer, you could use session variables. The alternative is to just pass them from page to page using hidden form fields, eg
<input name="yourvariable" type="hidden" value="<%=Request.Form("yourvariable")%>
There's no correct answer, it's a case of which you're most comfortable with
"get_user_info.asp"
<html>
<head></head>
<body>
<form id='frm_user_info' name='frm_user_info' method='post' action='get_user_info_go.asp'>
<table cellspacing='3'>
<tr>
<td align=right>Name</td>
<td><input type='text' id='s_name' name='s_name' size='40'></td>
</tr>
<tr>
<td></td>
<td><input type='submit' value='Next'></td>
</tr>
</table>
</form>
</body>
</html>
"get_user_info_go.asp"
<%
s_name=request.form("s_name")
if (s_name="") then response.redirect("get_user_info.asp")
session("s_name")=s_name
response.redirect("next_page.asp")
%>

VIsual Studio 2010 Design Mode Error Creating Control (Object reference not set)

Design mode has this problem site-wide since upgrading to .NET 4.0 / VS 2010 from 1.1 / 2003.
There's plenty to google on this and I've tried it all. What am I missing?
-Trying to debug from another instance of Visual Studio: Error Creating Control vs2010 MasterPage - there's not a whole lot of detail on how this is supposed to work. I started another empty instance of VS2010 and attached to devenv.exe. Set Debug->Break All. Switched to design mode in the website instance of VS. Ran the website instance of VS in debug mode. Nothing happens. I was hoping this could help because I DO have some user controls in the page. I can't find anything wrong with them though. Can I get more detail on how exactly to do this type of debugging? See the end of this post for the .aspx source.
-Commented out some <% =Session["Username"]%> junk in the tag of the page, since apparently accessing session stuff could cause this
-Checked the OnInit() method for dynamically adding controls or accessing uninstantiated objects. It's clean:
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cboURLFunction.SelectedIndexChanged += new System.EventHandler(this.cboURLFunction_SelectedIndexChanged_1);
this.cboStandard.SelectedIndexChanged += new System.EventHandler(this.cboStandard_SelectedIndexChanged);
this.cboType.SelectedIndexChanged += new System.EventHandler(this.cboType_SelectedIndexChanged);
this.chkLegacy.CheckedChanged += new System.EventHandler(this.chkLegacy_CheckedChanged);
this.btnRoute.Click += new System.EventHandler(this.btnRoute_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
.Aspx page source (thinned):
<%# Page language="c#" Codebehind="addRoute.aspx.cs" AutoEventWireup="false" Inherits="HTP.RHIO.WebPortal.addRoute" %>
<%# Register TagPrefix="HeaderControl" TagName="ucHeader" Src="ucHeader.ascx" %>
<%# Register TagPrefix="TopMenu" TagName="ucTopMenu" Src="ucTopMenu.ascx" %>
<%# Register TagPrefix="uc1" TagName="ucHelpLink" Src="ucHelpLink.ascx" %>
<HTML>
<HEAD>
<title>Add Route -
<% =Session["Domain"]%>
<% =Session["Username"]%>
</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<link href="./style/WebPortalMain.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
function jvsValidate() {
(removed for brevity)
}
</script>
</HEAD>
<body leftmargin="5" topmargin="0" rightmargin="5">
<form id="Form1" method="post" runat="server" onsubmit="return jvsValidate() ;">
<table id="Table1" class="tableWidth" cellspacing="0" cellpadding="0" border="0">
<!-- BEGIN HEADER ROW -->
<tr>
<td class="headerSection" colspan="3"><HeaderControl:ucHeader id="UcHeader1" runat="server"></HeaderControl:ucHeader></td>
</tr>
<!-- END HEADER ROW -->
<!-- BEGIN TOP NAV (IF NECCESSARY) -->
<tr>
<td class="topNavSection" colspan="3">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td style="WIDTH: 857px"><TopMenu:ucTopMenu id="UcTopMenu1" runat="server" xmlfilename="./MenuFiles/menu.xml" xslfilename="./MenuFiles/menu.xsl"></TopMenu:ucTopMenu></td>
<td align="right" width="15%"><uc1:ucHelpLink id="UcHelpLink1" runat="server"></uc1:ucHelpLink></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table id="Table2" class="tableWidth" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="3"><img src="graphics/servicers_routes.gif"></td>
<td align="right">
<asp:hyperlink id="backLink" runat="server">
<img src="./graphics/back.gif" border="0"></asp:hyperlink></td>
</tr>
.
.
etc
.
</table>
<!-- END MAIN BODY SECTION --></form>
</body>
</HTML>
you will find your answer there : http://blogs.msdn.com/b/webdev/archive/2010/05/06/another-error-creating-control-in-the-design-view-with-object-reference-not-set-in-visual-studio-2010.aspx

Javascript/DOM Why is does my form not support submit()?

This is my first time working with asp.net and javascript, so I don't know a lot of the nice web resources, or much about debugging javascript. I'm looking to find out why on line
oFormObject.submit(); Microsoft JScript runtime error: Object doesn't support this property or method.
I'm using links to function as buttons because I'm terrible at aesthetics and I think links will look more professional than a table of 50 buttons. I read that this solution may cause issues with browsers trying to pre-render my links and causing lots of extra traffic and problems, but the Css I found to make a button look like a link seemed to have alignment and spacing issues.
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><link rel="stylesheet" type="text/css" href="DefectSeverity.css" /><title>
Defect Severity Assessment Code List
</title></head>
<body>
<form name="form1" method="post" action="CodeList.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNjQzMTI3NjU4ZGSW2wNBW3eGztyO+Tftc5BB8A6cMg==" />
</div>
<div>
<p>Welcome Maslow</p><SCRIPT language="JavaScript">
function submitForm(intId)
{ oFormObject= document.getElementById(""form"+_StrCodeId + #""");
oFormElement= document.getElementById("codeId");
oFormElement.value=intId;
oFormObject.submit();
}
</SCRIPT> <form method="post" action="CodeAssessment.aspx" id="formcodeId">
<table name="codeId" id="codeId" value="0" type="hidden" class="linkTable">
<tr>
<th>Completed</th><th>Code</th><th>Description</th><th>Code Present Since</th>
</tr><tr class="row">
<td><input name="401" type="checkbox" value="401" DISABLED /></td><td>401</td><td>Missing Original Document/form</td><td>2009.10.16</td>
</tr><tr class="rowAlternate">
<td><input name="NDMI" type="checkbox" checked="checked" value="NDMI" DISABLED /></td>
<td>NDMI</td>
<td>Note date is missing</td> <td>2009.10.15</td>
</tr>
</table><input type="submit" />
</form>
</div>
</form>
</body>
</html>
If I change the script line to oFormObject= document.forms[0]; it submits the asp.net's viewstate form posting back to the same page instead of where I want to go. so the rest of the code on the page appears to work.
So we solved this in another answer, but using comments, so this is just incase anyone else has the same problem,
It's all down to the form having a runat="server" attribute, this generates the viewstate input, then when the form is submitted to the second page, it tries to fill out the page with the details from the viewstate, however as in this case the form is submitted to another page, the two pages don't match up and when it tries to deal with the viewstate input it throws the error.
The solution is to either remove the runat="server" attribute on the form, or to set EnableViewStateMac="False" attribute from the second page.
I'm not really into asp.net but into javascript, so I'd say there's a parse error in
oFormObject= document.getElementById(""form"+_StrCodeId + #""");
the quotes just don't match. i'd say you try to change it to
oFormObject= document.getElementById("formcodeId");
instead
Ok apparently you can't nest forms in html/DOM. I have changed my asp.net provided form and now it navigates but crashes saying
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><link rel="stylesheet" type="text/css" href="DefectSeverity.css" /><title>
Defect Severity Assessment Code List
</title></head>
<body>
<form name="form1" method="post" action="CodeAssessment.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNjQzMTI3NjU4ZGSW2wNBW3eGztyO+Tftc5BB8A6cMg==" />
</div>
<div>
<p>Welcome Maslow</p><SCRIPT language="JavaScript">
function submitForm(intId)
{ oFormObject= document.forms[0];
oFormElement= document.getElementById("codeId");
oFormElement.value=intId;
oFormObject.submit();
}
</SCRIPT> <table name="codeId" id="codeId" value="0" type="hidden" class="linkTable">
<tr>
<th>Completed</th><th>Code</th><th>Description</th><th>Code Present Since</th>
</tr><tr class="row">
<td><input name="401" type="checkbox" value="401" DISABLED /></td>
<td>401</td><td>Missing Original Document/form</td><td>2009.10.16</td>
</tr><tr class="rowAlternate">
<td><input name="NDMI" type="checkbox" checked="checked" value="NDMI" DISABLED /></td>
<td>NDMI</td><td>Note date is missing</td><td>2009.10.15</td>
</tr>
</table><input id="testSubmit" type="submit" />
</div>
</form>
</body>
</html>
I don't see what the issue is now, the code you posted in your answer worked fine for me, only problem I have is that I dont have a CodeAssesment.aspx page so I get a HTML404 error, but thats it.
Your original code document.getElementById(""form"+_StrCodeId + #"""); was not valid, and you don't have a variable called StrCodeId,
Try
oFormObject = document.getElementById("form"+intId);
Ok solved the crashing, so I put another answer, its because you've copied the source code and used that to create the outline again, I think, as you shouldn't have the hidden input viewstate as part of the page, it gets generated automatically on build. Remove this line and try it
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNjQzMTI3NjU4ZGSW2wNBW3eGztyO+Tftc5BB8A6cMg==" />
&lt/div>
I trimmed out my dynamic code generation section
<?xml version="1.0" encoding="UTF-8"?>
<!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><link rel="stylesheet" type="text/css" href="DefectSeverity.css" /><title>
Defect Severity Assessment Code List
</title><script type="text/javascript">
function submitForm(intId)
{ oFormObject= document.forms[0];
oFormElement= document.getElementById("codeId");
oFormElement.value=intId;
oFormObject.submit();
}
</script> </head>
<body>
<form name="form1" method="post" action="CodeAssessment.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMzMxMzk5NjY5ZGTQg8pLRPHaRM4Idd6LyKDmFvMpNA==" />
</div>
<div>
<input type="submit" />
</div>
</form>
</body>
</html>
Hey look there's another div again. I don't see where this is coming from. and I'm still getting Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Resources