How to get variable passed from input box to another page [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to get a variable from hidden INPUT text box to another page. I created a search.asp page, when I search a Form from this page, clicked search button, then view.asp page will open with that specific Form ID. On View.asp page, I created a link to open a new page called view2.asp that keeps the same Form ID. But it didn't work. Can you please help? Thanks.
view.asp code
<%#LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!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>Menus Search</title>
</head>
<body>
<style>
table, td, th {
border: 1px solid #ddd;
}
th, td {
padding: 3px;
}
</style>
</head>
<body>
<!--#include file="openConn.asp" -->
<%
SET objRS = Server.CreateObject("ADODB.Recordset")
SET objRS1 = Server.CreateObject("ADODB.Recordset")
SET objRS2 = Server.CreateObject("ADODB.Recordset")
SET objRS3 = Server.CreateObject("ADODB.Recordset")
If Request.Form("FormSource") = "SubmitForm" Then
For j = 1 to Request.Form("txtCount")-1
strReport = Request.Form("Report[" & j &"]")
strValue = split(strReport,"$")
sMenuID = strValue(0)
sCategoryID = strValue(1)
sStatus = strValue(2)
'response.write strReport & "::" & sMenuID & "::" & sCategoryID & "::" & sStatus & "<br>"
'response.end
sFormID = Request.Form("FormID")
sSQL = "INSERT INTO Report (FormID, MenuID, CategoryID, Status) VALUES " &_
"('" & sFormID & "', '" & sMenuID & "', '" & sCategoryID & "', '" & sStatus & "');"
objConn.Execute(sSQL)
Next
End If
%>
<form action="" method="post" id="newMenu" name="frmReport" onsubmit="return validateForm(this)">
<p>
<%
'''' RR added today
nFormID= Request("FormID") ''Request.Form("SearchObj")
response.write "FormID: " & nFormID & "<br>"
sSQL2 = "SELECT * FROM Form WHERE Formid = " & nFormID
''response.write "SQL:::: " & sSQL2 & "<br>"
objRS2.Open sSQL2, objConn
'response.Write sSQL2
Do Until objRS2.EOF
sFormName = objRS2("Form_Name")
%>
<h2><%= objRS2("Form_Name") %></h2>
<p><a href="#" onclick="openview2.asp();"/>Click me</a></p>
<input type="hidden" id="idFormName" name="FormID" size="40" maxlength="50" value="<%= objRS2("FormID") %>"><br />
<%
objRS2.MoveNext
Loop
objRS2.Close
%>
<p>
<table>
<thead bgcolor="#336666" style="color:#FFFFFF">
<tr>
<td>Trainer Name:</td>
<td>Pass</td>
<td>Fail</td>
<td>NA</td>
<td>Not taken</td>
</tr>
</thead>
<%
currMenu = ""
sSQL = "SELECT MenuID, Menu_Name FROM Menu where MENUID in (SELECT MENUID FROM Category where formid=" & nFormID & ")"
objRS.Open sSQL, objConn
i=1
While Not objRS.EOF
nMenuID = objRS("MenuID")
sMenuName = objRS("Menu_Name")
If currMenu <> sMenuName Then
currMenu = sMenuName
%>
<tr>
<th bgcolor="#CCCCCC"><%= sMenuName %></th>
</tr>
<input type="hidden" name="MenuID" value="<%=nMenuID%>">
<%
End If
sSQL3 = "SELECT Categoryid, Category_Name FROM Category WHERE MenuID = " & nMenuID & " and FormID=" & nFormID
Set objRS3 = Server.CreateObject("ADODB.Recordset")
objRS3.Open sSQL3, objConn
While Not objRS3.EOF
nCategoryID = objRS3("Categoryid")
sCategoryName = objRS3("Category_Name")
%>
<tr>
<td><%= sCategoryName %></td>
<input type="hidden" name="CategoryID" value="<%=nCategoryID%>">
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$1"></td>
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$2"></td>
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$3"></td>
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$4"></td>
</tr>
<%
objRS3.MoveNext
i = i + 1
Wend
objRS3.Close
objRS.MoveNext
Wend
objRS.Close
%>
</table>
</p>
<p>
<input type="hidden" name="txtCount" value="<%= i %>">
<input type="button" value="Create Menu" onclick="openwin();" />
<input type="hidden" name="FormSource" value="SubmitForm">
<input type="button" value="View2" onclick="openview2();" />
<input type="submit" value="Update">
Go To Search
</p>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript" ></script>
<script type="text/javascript">
function validateForm(daForm) {
nCount = document.frmReport.txtCount.value;
// check all rb radio buttons
for (var i = 1; i < nCount; i++) {
if (! getCheckedRadioValue(daForm["Report"+i])) {
alert ("Please select a value for option " + i)
return false
}
}
// add other checks here...
return true
}
function getCheckedRadioValue(radio) {
for (var i=0; i < radio.length; i++) {
if (radio[i].checked) return radio[i].value
}
return false
}
function openwin()
{
//alert($('#idFormName').val());
//window.location.href = "Create.asp?FormID=" + $('#idFormName').val();
window.open("Create.asp?FormID=" + $('#idFormName').val(), "Create New Menu", "menubar=0,width=700,height=450");
}
function openView2()
{
alert($('#idFormName').val());
window.open("view2.asp?FormID=" + $('#idFormName').val(), "Create New Menu", "menubar=0,width=700,height=450");
}
</script>
</body>
</html>
view2.asp
<%#LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!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>Menus Search</title>
</head>
<body>
<style>
table, td, th {
border: 1px solid #ddd;
}
th, td {
padding: 3px;
}
</style>
</head>
<body>
<!--#include file="openConn.asp" -->
<%
SET objRS = Server.CreateObject("ADODB.Recordset")
SET objRS1 = Server.CreateObject("ADODB.Recordset")
SET objRS2 = Server.CreateObject("ADODB.Recordset")
SET objRS3 = Server.CreateObject("ADODB.Recordset")
If Request("FormID")="" then
iFormID =0
Else
iFormID = Request("FormID") ''Request.Form("FormID")
End If
If Request.Form("FormSource") = "SubmitForm" Then
For j = 1 to Request.Form("txtCount")-1
strReport = Request.Form("Report[" & j &"]")
strValue = split(strReport,"$")
sMenuID = strValue(0)
sCategoryID = strValue(1)
sStatus = strValue(2)
'response.write strReport & "::" & sMenuID & "::" & sCategoryID & "::" & sStatus & "<br>"
'response.end
sFormID = Request.Form("FormID")
sSQL = "INSERT INTO Report (FormID, MenuID, CategoryID, Status) VALUES " &_
"('" & sFormID & "', '" & sMenuID & "', '" & sCategoryID & "', '" & sStatus & "');"
objConn.Execute(sSQL)
Next
End If
%>
<form action="" method="post" id="newMenu" name="frmReport" onsubmit="return validateForm(this)">
<p>
<%
'''' RR added today
nFormID= Request("FormID") ''Request.Form("SearchObj")
response.write "FormID: " & nFormID & "<br>"
sSQL2 = "SELECT * FROM Form WHERE Formid = " & nFormID
''response.write "SQL:::: " & sSQL2 & "<br>"
objRS2.Open sSQL2, objConn
'response.Write sSQL2
Do Until objRS2.EOF
sFormName = objRS2("Form_Name")
%>
<h2><%= objRS2("Form_Name") %></h2>
<input type="hidden" id="idFormName" name="FormID" size="40" maxlength="50" value="<%= objRS2("FormID") %>"><br />
<%
objRS2.MoveNext
Loop
objRS2.Close
%>
<p>
<table>
<thead bgcolor="#336666" style="color:#FFFFFF">
<tr>
<td>Trainer Name:</td>
<td>Pass</td>
<td>Fail</td>
<td>NA</td>
<td>Not taken</td>
</tr>
</thead>
<%
currMenu = ""
sSQL = "SELECT MenuID, Menu_Name FROM Menu where MENUID in (SELECT MENUID FROM Category where formid=" & nFormID & ")"
objRS.Open sSQL, objConn
i=1
While Not objRS.EOF
nMenuID = objRS("MenuID")
sMenuName = objRS("Menu_Name")
If currMenu <> sMenuName Then
currMenu = sMenuName
%>
<tr>
<th bgcolor="#CCCCCC"><%= sMenuName %></th>
</tr>
<input type="hidden" name="MenuID" value="<%=nMenuID%>">
<%
End If
sSQL3 = "SELECT Categoryid, Category_Name FROM Category WHERE MenuID = " & nMenuID & " and FormID=" & nFormID
Set objRS3 = Server.CreateObject("ADODB.Recordset")
objRS3.Open sSQL3, objConn
While Not objRS3.EOF
nCategoryID = objRS3("Categoryid")
sCategoryName = objRS3("Category_Name")
%>
<tr>
<td><%= sCategoryName %></td>
<input type="hidden" name="CategoryID" value="<%=nCategoryID%>">
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$1"></td>
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$2"></td>
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$3"></td>
<td align="center"><input type="radio" id ="Report<%=i%>" name="Report[<%=i%>]" value="<%=nMenuID%>$<%=nCategoryID%>$4"></td>
</tr>
<%
objRS3.MoveNext
i = i + 1
Wend
objRS3.Close
objRS.MoveNext
Wend
objRS.Close
%>
</table>
</p>
<p>
<input type="hidden" name="txtCount" value="<%= i %>">
<input type="button" value="Create Menu" onclick="openwin();" />
<input type="hidden" name="FormSource" value="SubmitForm">
<input type="submit" value="Update">
Go To Search
</p>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript" ></script>
<script type="text/javascript">
function validateForm(daForm) {
nCount = document.frmReport.txtCount.value;
// check all rb radio buttons
for (var i = 1; i < nCount; i++) {
if (! getCheckedRadioValue(daForm["Report"+i])) {
alert ("Please select a value for option " + i)
return false
}
}
// add other checks here...
return true
}
function getCheckedRadioValue(radio) {
for (var i=0; i < radio.length; i++) {
if (radio[i].checked) return radio[i].value
}
return false
}
</script>
</body>
</html>

It's hard to understand what you are trying to do.
But as I could understand, you want to open view2.asp and be able to have a value from view.asp there.
As I can see you open view2.asp with this line
<input type="button" value="View2" onclick="openview2();" />
And you want this hidden input
<input type="hidden" id="idFormName" name="FormID" size="40" maxlength="50" value="<%= objRS2('FormID') %>">
If this is what you are trying to do. Then your naming is wrong with the javascript. You probably copied and forgot to change name.
See here, where you try to open view2.asp
function openwin()
{
window.openView2("view2.asp?FormID=" + $('#idFormName').val(), "Create New Menu", "menubar=0,width=700,height=450");
}
You need to change openwin() to openview2()
EDIT:
I just also saw you have this strange code
<a href="#" onclick="openview2.asp();"/>Click me</a>
Which is a link to it self, because you have href="#". But you also trying to call a javascript function with this onclick="openview2.asp();".
You do not have a function called openview2.asp(). And this is not how it works.
If you are trying to call view2.asp with this link and pass the hidden input idFormName. Then it's better if you just do a correct link and pass the ID in the url.
I must say it's a very bad solution, because there is no security here. But the code you provided shows that you are only after a function and ignoring any security aspect.
So change this
<h2><%= objRS2("Form_Name") %></h2>
<p><a href="#" onclick="openview2.asp();"/>Click me</a></p>
<input type="hidden" id="idFormName" name="FormID" size="40" maxlength="50" value="<%= objRS2("FormID") %>"><br />
for this
<h2><%= objRS2("Form_Name") %></h2>
<p><a href="view2.asp?idFormName=<%= objRS2("FormID") %>" />Click me</a></p>
<input type="hidden" id="idFormName" name="FormID" value="<%= objRS2("FormID") %>"><br />
I'm leaving the hidden there in case you refer to this somewhere else in your code.
Good luck and Have a nice day!

Related

java script doesn't get the data from jsp

It's about search and paging functions.
this shows keyWord and keyField well on console when i search keyWord .
<%
String keyWord = (String)request.getParameter("keyWord");
String keyField = (String)request.getParameter("keyField");
System.out.println(keyWord);
System.out.println(keyField);
%>
but this doesn't work.
address appear like this. didn't get data from javascript code.
http://localhost:8090/mvcBoard/list.do?page=2&keyWord=&keyField=
function PageMove(page){
var keyWord = '<%request.getParameter("keyword");%>';
var keyField = '<%request.getParameter("keyField");%>';
console.log(keyWord);
location.href = "list.do?page="+page+"&keyWord=" + keyWord + "&keyField=" + keyField;
}
but it works!
location.href = "list.do?page="+page;
this is list.jsp
<!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=UTF-8">
<title>Insert title here</title>
<%
String keyWord = (String)request.getParameter("keyWord");
String keyField = (String)request.getParameter("keyField");
System.out.println(keyWord);
System.out.println(keyField);
%>
<script>
function searchCheck(frm){
//검색
if(frm.keyWord.value ==""){
alert("검색 단어를 입력하세요.");
frm.keyWord.focus();
return;
}
frm.submit();
}
function PageMove(page){
var keyWord = '<%request.getParameter("keyword");%>';
var keyField = '<%request.getParameter("keyField");%>';
console.log(keyWord);
if(keyWord){
location.href = "list.do?page="+page+"&keyWord=" + keyWord + "&keyField=" + keyField;
}
location.href = "list.do?page="+page+"&keyWord=" + keyWord + "&keyField=" + keyField;
}
</script>
</head>
<body>
<table width="800" cellpadding="0" cellspacing="0" border="1">
<tr>
<td>번호</td>
<td>이름</td>
<td>제목</td>
<td>날짜</td>
<td>조히수</td>
</tr>
<c:forEach items="${list}" var="dto">
<tr>
<td>${dto.bId}</td>
<td>${dto.bName}</td>
<td>
<c:forEach begin="1" end="${dto.bIndent}">-</c:forEach>
${dto.bTitle}</td>
<td>${dto.bDate}</td>
<td>${dto.bHit}</td>
</tr>
</c:forEach>
<tr>
<td colspan="5">
<form action="list.do" method="post" name="search">
<select name="keyField">
<option value="bTitle">글 제목</option>
<option value="bContent">글 내용</option>
<option value="bName">작성자</option>
</select>
<input type="text" name="keyWord">
<input type="button" value="검색" onclick="searchCheck(form)">
<input type="hidden" id=keyField value="${paging.keyField}">
<input type="hidden" id=keyWord value="${paging.keyWord}">
</form>
</td>
</tr>
<tr>
<td colspan="5"> 글작성 </td>
</tr>
</table>
<%-- <%=PageAction.pageNumber() %>
--%>
<div class="toolbar-bottom">
<div class="toolbar mt-lg">
<div class="sorter">
<ul class="pagination">
<li>맨앞으로</li>
<li>앞으로</li>
<c:forEach var="i" begin="${paging.startPageNo}" end="${paging.endPageNo}" step="1">
<c:choose>
<c:when test="${i eq paging.pageNo}">
<li class="active">${i}</li>
</c:when>
<c:otherwise>
<li>${i}</li>
</c:otherwise>
</c:choose>
</c:forEach>
<li>뒤로</li>
<li>맨뒤로</li>
</ul>
</div>
</div>
</div>
</body>
</html>
For a start this code looks wrong
<input type="hidden" value="${paging.getkeyField()}">
<input type="hidden" value="${paging.getKeyWord()}">
change to the same format as paging.nextPageNo
<input type="hidden" value="${paging.keyField}">
<input type="hidden" value="${paging.keyWord}">
next you either add an id to this hidden fields (and get the value using Javascript or jquery)
<input type="hidden" id="kf" value="${paging.keyField}">
or use the same parameter passing as paging.nextPageNo to PageMove
javascript:PageMove(${paging.nextPageNo}, ${paging.keyField}); // etc

How to get values from an option being selected

I have a Users table that has User_id, Firstname, Lastname, and Role. I like to create a classic ASP page to display values when an option is selected. Whenever I select a username from the drop-down box, then it displays its values below. I tried that but it didn't do anything when I select a username in the drop-down.
Here is my code:
User_id Firstname Lastname Role
-------------------------------------
1 Jenny Rogers A
2 Jenny2 Rogers2 B
1 Jenny Rogers B
2 Jenny2 Rogers2 A
3 Jenny3 Rogers3 C
ASP code:
<form action="" method="post" id="newMenu" name="frmReport" onSubmit="return validateForm(this)">
<table>
<thead>
<tr>
<td>
<strong>New User: </strong>
<select name="UserID">
<option value="">All Users</option>
<% sSQL = "SELECT DISTINCT User_id, Lastname, Firstname FROM User "
objRS.Open sSQL, objConn
Do Until objRS.EOF
Response.Write("<option value='" & objRS("User_id") & "'>" & objRS("Lastname") & ", " & objRS("Firstname") & "</option>")
objRS.MoveNext
Loop
objRS.Close
%>
</select>
<%
If Len("UserID") > 0 Then
sSQL = "SELECT User_id, Role FROM Users WHERE User_id = '" & request.Form("UserID") & "' ; "
objRS.Open sSQL, objConn
Do Until objRS.EOF
%>
<input type="text" name="Role" value="<%= objRS(" Role ") %>">
<% objRS.MoveNext
Loop
objRS.Close
End If
%>
<input type="hidden" name="FormSource" value="SubmitForm">
<input type="submit" value="Submit Form">
</th>
</tr>
</table>
</form>
Maybe this is what you want
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/BUYIN.asp" -->
<%
''''''Recordset with Names
Dim objRS
Dim objRS_cmd
Dim objRS_numRows
Set objRS_cmd = Server.CreateObject ("ADODB.Command")
objRS_cmd.ActiveConnection = MM_BUYIN_STRING
objRS_cmd.CommandText = "SELECT id, FirstName, LastName FROM dbo.BI_Users WHERE firstname like '%test%'"
objRS_cmd.Prepared = true
Set objRS = objRS_cmd.Execute
objRS_numRows = 0
%>
<!--Results -->
<% If Request.Form("selectID") <> "" Then %>
<%
Dim rsResults__getID
rsResults__getID = "0"
If (Request.Form("selectID") <> "") Then
rsResults__getID = Request.Form("selectID")
End If
%>
<%
Dim rsResults
Dim rsResults_cmd
Dim rsResults_numRows
Set rsResults_cmd = Server.CreateObject ("ADODB.Command")
rsResults_cmd.ActiveConnection = MM_BUYIN_STRING
rsResults_cmd.CommandText = "SELECT id, FirstName, LastName, fkRoleID FROM dbo.BI_Users WHERE id = ?"
rsResults_cmd.Prepared = true
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param1", 5, 1, -1, rsResults__getID) ' adDouble
Set rsResults = rsResults_cmd.Execute
rsResults_numRows = 0
%>
<% End If %>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="testasp2.asp">
<select name="selectID" id="selectID">
<%
While (NOT objRS.EOF)
%>
<option value="<%=(objRS.Fields.Item("id").Value)%>" <%If (Not isNull(Request.Form("selectID"))) Then If (CStr(objRS.Fields.Item("id").Value) = CStr(Request.Form("selectID"))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(objRS.Fields.Item("LastName").Value)%></option>
<%
objRS.MoveNext()
Wend
If (objRS.CursorType > 0) Then
objRS.MoveFirst
Else
objRS.Requery
End If
%>
</select>
<input type="submit" name="button" id="button" value="Submit" />
</form>
<hr />
<% If Request.Form("selectID") <> "" Then %>
<% If Not rsResults.EOF Or Not rsResults.BOF Then %>
<p><%=(rsResults.Fields.Item("id").Value)%> </p>
<p><%=(rsResults.Fields.Item("FirstName").Value)%> </p>
<p><%=(rsResults.Fields.Item("LastName").Value)%> </p>
<p><%=(rsResults.Fields.Item("fkRoleid").Value)%> </p>
<%
rsResults.Close()
Set rsResults = Nothing
%>
<% End If %>
<% Else %>
<%= "No Results Yet" %>
<% End If %>
</body>
</html>
<%
objRS.Close()
Set objRS = Nothing
%>

Generate an error if number is repeated in a form

I have a web form for admin purposes where the user can change the order that a group of records is shown on a webpage.
For example: A table (tblStuff) in a database has three fields:
ContentID, Content, RecordPosition
The table has, say, four records:
1, Guess what, 1
2, More stuff, 2
3, Some stuff, 3
4, That's right, 4
The SQL code is:
SELECT * FROM tblStuff ORDER BY RecordPosition ASC
The user can use the form to change the RecordPosition number so that the order can read:
3, Some stuff, 1
2, More stuff, 2
1, Guess what, 3
4, That's right, 4
So... How can I validate the form so that the same number isn't entered twice into the RecordPosition field?
Hope this makes sense.
Here's the whole page
<%#LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include virtual="/Connections/ENG.asp" -->
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="../default.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
If Request.Form("action")="update" Then
'Set variables for update
Dim updateSQL, i
Dim cContentID, cPositionNumber
'Loop through records on screen and update
For i = 1 To fFormat(Request.Form("counter"))
'Create the proper field names to reference on the form
cContentID = "ContentID" & CStr(i)
cPositionNumber = "PositionNumber" & CStr(i)
'Create the update sql statement
updateSQL = "UPDATE tblContent SET PositionNumber=" & fFormat(Request.Form(cPositionNumber)) & " WHERE ContentID=" & fFormat(Request.Form(cContentID))
'Run the sql statement
Call sRunSQL(updateSQL)
Next
'Refresh page
Response.Redirect("record-order-modify-updated.asp")
End If
Function fFormat(vText)
fFormat = Replace(vText, "'", "''")
End Function
Sub sRunSQL(vSQL)
set cExecute = Server.CreateObject("ADODB.Command")
With cExecute
.ActiveConnection = MM_ENG_STRING
.CommandText = vSQL
.CommandType = 1
.CommandTimeout = 0
.Prepared = true
.Execute()
End With
End Sub
%>
<%
Dim rsCharityDetails
Dim rsCharityDetails_cmd
Dim rsCharityDetails_numRows
Set rsCharityDetails_cmd = Server.CreateObject ("ADODB.Command")
rsCharityDetails_cmd.ActiveConnection = MM_ENG_STRING
rsCharityDetails_cmd.CommandText = "SELECT * FROM tblCharityDetails"
rsCharityDetails_cmd.Prepared = true
Set rsCharityDetails = rsCharityDetails_cmd.Execute
rsCharityDetails_numRows = 0
%>
<%
Dim rsNavBar
Dim rsNavBar_cmd
Dim rsNavBar_numRows
Set rsNavBar_cmd = Server.CreateObject ("ADODB.Command")
rsNavBar_cmd.ActiveConnection = MM_ENG_STRING
rsNavBar_cmd.CommandText = "SELECT * FROM tblMainMenu WHERE MainMenuID <6 OR MainMenuID >7"
rsNavBar_cmd.Prepared = true
Set rsNavBar = rsNavBar_cmd.Execute
rsNavBar_numRows = 0
%>
<%
Dim rsContent__smID
rsContent__smID = "1"
If (Request.QueryString("smID") <> "") Then
rsContent__smID = Request.QueryString("smID")
End If
%>
<%
Dim rsContent
Dim rsContent_cmd
Dim rsContent_numRows
Set rsContent_cmd = Server.CreateObject ("ADODB.Command")
rsContent_cmd.ActiveConnection = MM_ENG_STRING
rsContent_cmd.CommandText = "SELECT tblContent.*, tblMainMenu.MainMenuName, tblSubMenu.SubMenuName, tblSubMenu.SubMenuID FROM (tblContent LEFT JOIN tblMainMenu ON tblContent.MainMenuID = tblMainMenu.MainMenuID) LEFT JOIN tblSubMenu ON tblContent.SubMenuID = tblSubMenu.SubMenuID WHERE tblContent.SubMenuID = ? AND tblContent.DisplayRecord =1 ORDER BY tblContent.PositionNumber"
rsContent_cmd.Prepared = true
rsContent_cmd.Parameters.Append rsContent_cmd.CreateParameter("param1", 5, 1, -1, rsContent__smID) ' adDouble
Set rsContent = rsContent_cmd.Execute
rsContent_numRows = 0
%>
<%
Dim rsMenuList
Dim rsMenuList_cmd
Dim rsMenuList_numRows
Set rsMenuList_cmd = Server.CreateObject ("ADODB.Command")
rsMenuList_cmd.ActiveConnection = MM_ENG_STRING
rsMenuList_cmd.CommandText = "SELECT tblMainMenu.MainMenuID, tblMainMenu.MainMenuName, tblSubMenu.SubMenuID, tblSubMenu.SubMenuName FROM tblMainMenu INNER JOIN tblSubMenu ON tblMainMenu.MainMenuID = tblSubMenu.MainMenuID WHERE tblSubMenu.SubMenuID <> 6 AND tblSubMenu.SubMenuID <16 OR tblSubMenu.SubMenuID >19"
rsMenuList_cmd.Prepared = true
Set rsMenuList = rsMenuList_cmd.Execute
rsMenuList_numRows = 0
%>
<%
Dim rsHeaderImage
Dim rsHeaderImage_cmd
Dim rsHeaderImage_numRows
Set rsHeaderImage_cmd = Server.CreateObject ("ADODB.Command")
rsHeaderImage_cmd.ActiveConnection = MM_ENG_STRING
rsHeaderImage_cmd.CommandText = "SELECT MainMenuImage, MainMenuID FROM tblMainMenu"
rsHeaderImage_cmd.Prepared = true
Set rsHeaderImage = rsHeaderImage_cmd.Execute
rsHeaderImage_numRows = 0
%>
<%
Dim navBar__numRows
Dim navBar__index
navBar__numRows = -1
navBar__index = 0
rsNavBar_numRows = rsNavBar_numRows + navBar__numRows
%>
<%
Dim rptContent__numRows
Dim rptContent__index
rptContent__numRows = -1
rptContent__index = 0
rsContent_numRows = rsContent_numRows + rptContent__numRows
%>
<%
Dim Repeat_MenuList__numRows
Dim Repeat_MenuList__index
Repeat_MenuList__numRows = -1
Repeat_MenuList__index = 0
rsMenuList_numRows = rsMenuList_numRows + Repeat_MenuList__numRows
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="iso-8859-1">
<!-- disable iPhone inital scale -->
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title><%=(rsCharityDetails.Fields.Item("CharityName").Value)%> | English Website Administration</title>
<!-- main css -->
<link href="../../scripts/mfm-standard-stylesheet.css" rel="stylesheet" type="text/css">
<!--[if lt IE 9]>
<link href="../scripts/mfm-standard-stylesheet_ie.css" rel="stylesheet" type="text/css">
<![endif]-->
<!-- Admin css -->
<link href="../scripts/mfm-admin-stylesheet.css" rel="stylesheet" type="text/css">
<script src="../../scripts/jquery-1.7.2.min.js"></script>
<!-- jQuery NailThumb Plugin - any image to any thumbnail Examples and documentation at: http://www.garralab.com/nailthumb.php -->
<script src="../../scripts/jquery.nailthumb.1.1.js"></script>
<!-- Lightbox2 v2.51 by Lokesh Dhakar For more information, visit: http://lokeshdhakar.com/projects/lightbox2/ -->
<script src="../../scripts/lightbox.js"></script>
<!-- Lightbox css -->
<link href="../../scripts/lightbox.css" rel="stylesheet" type="text/css" media="screen" />
<script src="../tiny_mce/tiny_mce.js"></script>
<script src="../tiny_mce/tiny-mce-mfm.js"></script>
<!-- html5.js for IE less than 9 -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- css3-mediaqueries.js for IE less than 9 -->
<!--[if lt IE 9]>
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
</head>
<body id="other">
<div id="wrapper">
<header class="innerWidth">
<!--#include file="includes/header-modify-record.asp" -->
</header>
<nav class="innerWidth">
<!--#include file="includes/navbar-modify-record.asp" -->
</nav>
<!-- pageContent -->
<div id="content" class="innerWidth">
<!-- Aside -->
<aside>
<h3>Record Order</h3>
<ul>
<%
Dim txtOldHeading
txtOldHeading = ""
While ((Repeat_MenuList__numRows <> 0) AND (NOT rsMenuList.EOF))
If txtOldHeading = rsMenuList.Fields.Item("MainMenuName").Value Then
Else
txtOldHeading = rsMenuList.Fields.Item("MainMenuName").Value
%>
<li class="menuHeading"><%=(rsMenuList.Fields.Item("MainMenuName").Value)%></li>
<%
END IF
%>
<li class="menuList">
<% If (rsMenuList.Fields.Item("SubMenuID").Value) = "3" Then %>
<%=(rsMenuList.Fields.Item("SubMenuName").Value)%>
<% ElseIf (rsMenuList.Fields.Item("SubMenuID").Value) = "15" Then %>
<%=(rsMenuList.Fields.Item("SubMenuName").Value)%>
<% ElseIf (rsMenuList.Fields.Item("SubMenuID").Value) = "20" Then %>
<%=(rsMenuList.Fields.Item("SubMenuName").Value)%>
<% Else %>
<%=(rsMenuList.Fields.Item("SubMenuName").Value)%>
<% End If %>
</li>
<%
Repeat_MenuList__index=Repeat_MenuList__index+1
Repeat_MenuList__numRows=Repeat_MenuList__numRows-1
rsMenuList.MoveNext()
Wend
%>
</ul>
</aside>
<!-- /Aside -->
<!-- Article -->
<article>
<% IF Request.ServerVariables("QUERY_STRING") <> "" THEN %>
<h3><span style="font-size:small">Order/Re-order records for: </span><%=(rsContent.Fields.Item("SubMenuName").Value)%></h3>
<%
Dim counter
While ((rptContent__numRows <> 0) AND (NOT rsContent.EOF))
counter = counter + 1
%>
<form action="record-order-modify.asp" method="post" class="recordPosition">
<table width="100%">
<tr>
<td align="left" valign="top" name="ContentTitle" colspan="2"><h2><%=(rsContent.Fields.Item("ContentTitle").Value)%></h2><input type="hidden" value="<%=(rsContent.Fields.Item("ContentID").Value)%>" name="ContentID<%=counter%>"></td>
</tr>
<tr>
<td align="left" valign="top" name="ContentData"><%
Dim tmp
tmp = rsContent.Fields.Item("ContentData").Value
%>
<% =LEFT(tmp, INSTR((tmp & "."), ".")) %>..
</td>
<% IF (IsNull(rsContent.Fields.Item("ContentImage").Value)) THEN %>
<td width="140" align="center" valign="top" name="ContentImage"><img src="../images/system_images/red-x.png"></td>
<% ELSE %>
<td width="140" align="center" valign="top" name="ContentImage"><div class="nailthumb-container">
<!-- Thumbnail Container -->
<img src="<%=(rsContent.Fields.Item("ContentImage").Value)%>"> </div></td>
<% END IF %>
</tr>
<tr>
<td align="left"><label>Current Record Position: <small class="brown" style="text-transform:none">(You may change it here)</small></label> <input type="text" name="PositionNumber<%=counter%>" tabindex="<%=counter%>" value="<%=(rsContent.Fields.Item("PositionNumber").Value)%>"></td>
</tr>
</table>
<hr>
<%
rptContent__index=rptContent__index+1
rptContent__numRows=rptContent__numRows-1
rsContent.MoveNext()
Wend
%>
<table align="center" class="positionButtons">
<tr>
<td width="50%" align="right"><input name="Submit" type="submit" value="Update Positions" tabindex="<%=counter%>"></td>
<td width="50%" align="left"><input name="Reset" type="reset" value="Reset All Changes" tabindex="<%=counter%>"></td>
</tr>
</table>
<input type="hidden" name="action" value="update">
<input type="hidden" name="counter" value="<%=counter%>">
</form>
<% ELSE %>
<h3>Select a listing to order/re-order using the list on the left.</h3>
<% END IF %>
</article>
<!-- /Article -->
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.nailthumb-container').nailthumb({width:125,height:125,fitDirection:'top center'});
});
</script>
</div>
<!-- /pageContent -->
<div class="push"></div>
</div>
<!-- #wrapper -->
<footer class="innerWidth">
<!--#include file="includes/footer.asp" -->
</footer>
</body>
</html>
<%
rsCharityDetails.Close()
Set rsCharityDetails = Nothing
%>
<%
rsNavBar.Close()
Set rsNavBar = Nothing
%>
<%
rsContent.Close()
Set rsContent = Nothing
%>
<%
rsMenuList.Close()
Set rsMenuList = Nothing
%>
<%
rsHeaderImage.Close()
Set rsHeaderImage = Nothing
%>
As requested by Allende, here's the generated form code.
<form action="record-order-modify.asp" method="post" class="recordPosition">
<table width="100%">
<tr>
<td align="left" valign="top" name="ContentTitle" colspan="2"><h2>Investing in people and the environment</h2><input type="hidden" value="15" name="ContentID1"></td>
</tr>
<tr>
<td align="left" valign="top" name="ContentData"><p>Madagascar is an environmental hotspot...
</td>
<td width="140" align="center" valign="top" name="ContentImage"><div class="nailthumb-container">
<!-- Thumbnail Container -->
<img src="/images/framed-images/mfm-website-(26).jpg"> </div></td>
</tr>
<tr>
<td align="left"><label>Current Record Position: <small class="brown" style="text-transform:none">(You may change it here)</small></label> <input type="text" name="PositionNumber1" tabindex="1" value="1"></td>
</tr>
</table>
<hr>
<table width="100%">
<tr>
<td align="left" valign="top" name="ContentTitle" colspan="2"><h2>The next generation</h2><input type="hidden" value="16" name="ContentID2"></td>
</tr>
<tr>
<td align="left" valign="top" name="ContentData"><p>Teaching Malagasy children to respect and nurture their environment is critical to the survival of Madagascar's biodiversity...
</td>
<td width="140" align="center" valign="top" name="ContentImage"><div class="nailthumb-container">
<!-- Thumbnail Container -->
<img src="/images/framed-images/mfm-website-(292).jpg"> </div></td>
</tr>
<tr>
<td align="left"><label>Current Record Position: <small class="brown" style="text-transform:none">(You may change it here)</small></label> <input type="text" name="PositionNumber2" tabindex="2" value="2"></td>
</tr>
</table>
<hr>
<table width="100%">
<tr>
<td align="left" valign="top" name="ContentTitle" colspan="2"><h2>Recognition for our work</h2><input type="hidden" value="17" name="ContentID3"></td>
</tr>
<tr>
<td align="left" valign="top" name="ContentData"><p>Our work over 2 decades with 73 villages surrounding the Reserve of Betampona recently gained recognition at an international conference held at the University of East Anglia...
</td>
<td width="140" align="center" valign="top" name="ContentImage"><div class="nailthumb-container">
<!-- Thumbnail Container -->
<img src="/images/framed-images/mfm-website-(56).jpg"> </div></td>
</tr>
<tr>
<td align="left"><label>Current Record Position: <small class="brown" style="text-transform:none">(You may change it here)</small></label> <input type="text" name="PositionNumber3" tabindex="3" value="3"></td>
</tr>
</table>
<hr>
<table width="100%">
<tr>
<td align="left" valign="top" name="ContentTitle" colspan="2"><h2>Adding value by adding forests</h2><input type="hidden" value="18" name="ContentID4"></td>
</tr>
<tr>
<td align="left" valign="top" name="ContentData"><p>Often the best way to protect an old forest is to plant a new one...
</td>
<td width="140" align="center" valign="top" name="ContentImage"><div class="nailthumb-container">
<!-- Thumbnail Container -->
<img src="/images/framed-images/mfm-website-(217).jpg"> </div></td>
</tr>
<tr>
<td align="left"><label>Current Record Position: <small class="brown" style="text-transform:none">(You may change it here)</small></label> <input type="text" name="PositionNumber4" tabindex="4" value="4"></td>
</tr>
</table>
<hr>
<table align="center" class="positionButtons">
<tr>
<td width="50%" align="right"><input name="Submit" type="submit" value="Update Positions" tabindex="4"></td>
<td width="50%" align="left"><input name="Reset" type="reset" value="Reset All Changes" tabindex="4"></td>
</tr>
</table>
<input type="hidden" name="action" value="update">
<input type="hidden" name="counter" value="4">
</form>
Let's suppose you have form like this (notice all the inputs has the same class):
<form id="myForm" method="POST" action"someUrl">
<input type="text" class="recordPosition"></input>
<input type="text" class="recordPosition"></input>
<input type="text" class="recordPosition"></input>
<input type="text" class="recordPosition"></input>
</form>
You could do with jQuery something like this:
$(document).ready(function(){
$(".recordPosition").on("blur", function(){
var allFieldsForOrder = $('.recordPosition');
var count = 0;
var i=0
//console.log(allFieldsForOrder.length );
while((i<allFieldsForOrder.length) && (count < 2)){
if ($(allFieldsForOrder[i]).val()===$(this).val())
{
count++
}
i++;
}
if (count==2){
alert("A duplicated value"); return false;}
});
});
For the html you posted you can use this:
Notice I don't store the position of the duplicated the value.
$(document).ready(function(){
//console.log($("input[type='text'][name^='PositionNumber'").length);
$("input[type='text'][name^='PositionNumber'").each(function(){
$(this).on("blur", function(){
var allFieldsForOrder = $("input[type='text'][name^='PositionNumber'");
var count = 0;
var i=0
while((i<allFieldsForOrder.length) && (count < 2)){
if ($(allFieldsForOrder[i]).val()===$(this).val())
{
count++
}
i++;
}
if (count==2){
alert("A duplicated value");
}
});
});
});
For the code above we assume you want to check for all the fields where the attribute name starts with the string "PositionNumber"
I will try to reduce the code later, I think there's a shortest way to check if is duplicated the "RecordPosition" value, but need to test some ideas.
This will be your solution (one of them):
$(document).ready(function(){
$('form').on("submit",function(){
var tempArray=[];
$("input[type='text'][name^='PositionNumber'").each(function(){
tempArray.push($(this).val());
});
var i=0;
var duplicated=false;
var currentElement;
while((tempArray.length >= 0) && (duplicated==false)){
//pop it out from the array
currentElement = tempArray.pop();
duplicated = tempArray.indexOf(currentElement)
}
//after you can use "duplicated" to cancel the submit
if (duplicated){
alert("duplicated value:" + currentElement);
return false;
}
});
});
I shorter version:
$(document).ready(function(){
$('form').on("submit",function(){
var tempArray=[];
var exists=0;
$("input[type='text'][name^='PositionNumber'").each(function(){
exists = tempArray.indexOf($(this).val());
if (exists>=0){
return false;//break the loop
}
tempArray.push($(this).val());
});
//after you can use "exist" to check if duplicated and retrieve the value to cancel the submit
if (exists>=0){
alert("duplicated value:" + tempArray[exists]);
} else{
alert("no duplicated value:");
}
return false;
});
});
If you want to prevent duplicate values in RecordPosition no matter how you insert/update them you can create a unique constraint this column
CREATE UNIQUE INDEX uq_idx_RecordPosition ON tblStuff(RecordPosition);
Here is SQLFiddle demo
If you're trying to do some client-side validation, you'd have to build an array that contains all the RecordPosition values.
Once you have that, you can check the array for duplicates. This has been asked a couple of times on SO: Easiest way to find duplicate values in a JavaScript array
Unfortunately I can't help any more than that because you don't include any code that shows how this is structured on your web page
Check before inserting data in to data base
ex: recordposition value 3 --> 1 then pass value 1
SELECT * FROM tblStuff Where RecordPosition=1
if record exist then give message to user this position is exist

i want to write value in different textfield (rhodes and java)

i'm using rhostudio to create a mobile app. currently i do have this kind of codes
<div data-role="page">
<script type="text/javascript">
function call(harga,nama){
var quantity=prompt("Insert Quantity");
var pri=harga;
var nam="document.form1."+nama;
alert("unit price RM" + pri+".00");
price= quantity * pri;
alert(quantity);
alert("total price RM" + price+".00");
alert("total price RM" + price+".00" + " should be displayed into " + nam +" textfield");
document.form1."name".value = quantity;
nam.value = quantity;
document.form1."name".value = "RM " + price;
// document.form1.hidden3.value = nam;
}
</script>
<div data-role="header" data-position="inline">
<h1>Displays</h1>
<a href="<%= Rho::RhoConfig.start_path %>" class="ui-btn-left" data-icon="home" data-direction="reverse" <%= "data-ajax='false'" if is_bb6 %>>
Home
</a>
<a href="<%= url_for :action => :new %>" class="ui-btn-right" data-icon="plus">
New
</a>
</div>
<div data-role="content">
<form name="form1">
<table>
<tr align="center">
<td>Product</td>
<td>Quantity</td>
<td>Total Price</td></tr>
<% #products.each do |product| %>
<tr align="center">
<td><%= product.name %></td>
<td><input type="text" name="<%= product.name %>" value="textfield <%= product.name %>"></td>
<td><input type="text" name="<%= product.price %>" value="textfield <%= product.price %>"></td>
</tr>
<% end %>
</table>
<br/>
<br/>
<% #products.each do |product| %>
<input type="hidden" value="price :<%= product.price %>" name="harga"/>
<input type="button" onclick="call(<%= product.price%>,value);" name="Press" value="<%= product.name %>">
<% end %>
</form>
</div>
</div>
i called a function call once i pressed a button.each textfield have different name and value.same goes to the value of the button and value as parameter for function call. it suppost to write the result calculated in the call() function into the specific textfield. unfortunately, it does not! help me..
each text field has different name and it based on object created. since i have created many textfilelds based on the amount of object, is suppose to have different name and write the result into that textfield as well.unfortunately, it does not! help me..
You have lots of error through out the code man. Don't know what are you trying to achieve.
If you just want to pass the values of product.price and product.name to the call function, try this
<input type="button" onclick="call('<%= product.price %>','<%= product.price %>');" value="Press" />
Then on the function like below,
function call(harga,nama){
var quantity=prompt("Insert Quantity");
quantity = isNaN(parseFloat(quantity)) ? 0 : parseFloat(quantity);
var pri = isNaN(parseFloat(harga)) ? 0 : parseFloat(harga);
alert("unit price RM" + pri);
var price= quantity * pri;
alert("total price : " + price);
// specify your rest code over here
}
Hope this helps you.

asp and javascript message alert doesn't work

here's my code
<%
if request.form("Add") = " Add " then
if request.form("txtdistributor") = "" or request.form("sinumber") = "" or request.form("tstdate") = "" or request.form("drnumber") = "" or request.form("drdate") = "" or request.form("receivedby") = "" then
response.redirect("salesinvoice.asp?userloggedin=" &request.querystring("userloggedin") &"&dist=" &request.QueryString("dist") )
end if
SQLString = "INSERT INTO salesinvoice (distributor,sidate,sinumber) VALUES ('" & Request.form("txtdistributor") & "','" & Request.Form("tstdate") & "','" & Request.Form("sinumber") &"') "
set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open Application("dals_ConnectionString")
DBConn.Execute(SQLString)
DBConn.Close
set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open Application("dals_ConnectionString")
SQLString = "INSERT INTO Delivery_Receipt (Date_Purchase, Receipt_no, Distributor, Received_by, Entry_Date,sinumber) VALUES"
SQLString = SQLString & "('" & Request.Form("drdate") & "','" & Request.Form("drnumber") & "', '" & Request.Form("txtdistributor")& "','" & Request.Form("receivedby") & "','" & now() & "','" & request.Form("sinumber") & "')"
DBConn.Execute(SQLString)
DBConn.Close
response.Redirect("salesinvoice.asp?userloggedin=" &request.QueryString("userloggedin") &"&dist=" &request.QueryString("dist"))
end if
%>
<!-- Javascript -->
<script type="text/javascript">
function validateform()
{
if (document.frm.txtdistributor.value == '')
{
alert('Please input distributor');
document.frm.txtdistributor.focus();
return false;
}
if (document.frm.txtdistributor.value == '')
{
alert('Please input distributor');
document.frm.txtdistributor.focus();
return false;
}
if (document.frm.sinumber.value == '')
{
alert('Please input sales invoice number');
document.frm.sinumber.focus();
return false;
}
if (document.frm.tstdate.value == '')
{
alert('Please input sales invoice date');
document.frm.tstdate.focus();
return false;
}
if (document.frm.drnumber.value == '')
{
alert('Please input Delivery Receipt Number');
document.frm.drnumber.focus();
return false;
}
if (document.frm.drdate.value == '')
{
alert('Please input Delivery Receipt');
document.frm.drdate.focus();
return false;
}
if (document.frm.receivedby.value == '')
{
alert('Please input requestor');
document.frm.receivedby.focus();
return false;
}
return true;
}
</script>
<html>
<head>
<title>Sales Invoice</title>
</head>
<body>
<!--#include file="header.asp"-->
<form name="frm" id="frm" action="salesinvoice.asp?userloggedin=<%=request.QueryString("userloggedin")%>&dist=<%=request.QueryString("dist")%>" method="post" onSubmit="return validateform();">
<link href="css/calendar.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="calendar_date_picker.js"></script>
<script type="text/javascript">
var cdp1 = new CalendarDatePicker();
var props = {
debug : true,
excludeDays : [6,0,1],
excludeDates : ['20081225','20081226','20091225','20091226'],
minimumFutureDate : 5,
formatDate : '%m-%d-%y'
};
var cdp2 = new CalendarDatePicker(props);
props.formatDate = '%d-%m-%y';
var cdp3 = new CalendarDatePicker(props);
cdp3.endYear = cdp3.startYear + 1;
</script>
<table width="900" align="center">
<tr>
<td width="200">Distributor</td>
<td>
<%if request.querystring("dist") <> "yes" then%>
<select name="txtdistributor" style="width:260;">
<option value="">- Select -</option>
<%
strsql = "select Distinct(Distributor) from salesinvoice"
set rsdist = server.createobject("adodb.recordset")
rsdist.open strsql,application("dals_connectionstring")
while not rsdist.eof
%>
<option value="<%=rsdist("distributor")%>"><%=rsdist("distributor")%></option>
<%
rsdist.movenext
wend
rsdist.close
set rsdist = nothing
%>
</select> Add New Distributor
<%end if%>
<%if request.querystring("dist") <> "no" then%>
<input type="text" size="38" name="txtdistributor" id="txtdistributor"> [ - ]
<%end if%>
</td>
</tr>
<tr>
<td>SI Number</td>
<td><input type="text" name="sinumber" id="sinumber"></td>
</tr>
<tr>
<td>SI Date</td>
<td><input type="text" name="tstdate" id="txtdate" readonly> <img src="images/calendar.png" border="0" align="absmiddle" style="cursor:hand;" title="Calendar"></td>
</tr>
<tr>
<td>DR Number</td>
<td><input type="text" name="drnumber" id="drnumber"></td>
</tr>
<tr>
<td>DR date</td>
<td><input type="text" name="drdate" id="drdate" readonly> <img src="images/calendar.png" border="0" align="absmiddle" style="cursor:hand;" title="Calendar"></td>
</tr>
<tr>
<td>Received by</td>
<td>
<!--<input type="text" name="receivedby" id="receivedby">-->
<select name="receivedby" id="receivedby">
<option value="">- Select -</option>
<%
strsql = "select first_name,last_name from sysadusers"
set rsname = server.CreateObject("adodb.recordset")
rsname.open strsql,application("dals_connectionstring")
while not rsname.eof
%>
<option value="<%=rsname("first_name")%>, <%=rsname("last_name")%>"><%=rsname("first_name")%>, <%=rsname("last_name")%></option>
<%
rsname.movenext
wend
rsname.close
%>
</select>
You might have runtime error in the validation function, for example when the form does not contain the txtdistributor drop down.
For the sake of debugging, change the function to this only:
function validateform() {
alert("validation started");
var oDDL = document.frm.txtdistributor;
if (oDDL) {
if (oDDL.value == '') {
alert('Please input distributor');
oDDL.focus();
}
} else {
alert("form does not contain txtdistributor");
}
alert("validation ended");
return false;
}
If this works, apply the same logic for the rest of the fields and remove the debug messages.

Categories

Resources