I have a script and a Dinamic created Button and event OnClick doesn't work
I need to pass Id and inQuantidade to ValidarEstoqueVenda.htm and JavaScript is the only way i think its possible
page import="usuario.usuario"%>
<%#page import="DAO.DAO"%>
<%#page import="java.util.ArrayList"%>
<%#page import="produto.produto"%>
<%#page import="java.util.List"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<% usuario Usuario = (usuario) session.getAttribute("Usuario");%>
<script>
function clickVender(){
var Id = document.getElementById('Id');
var inQuantidade = document.getElementById('inQuantidade');
if(Id.value != "")
alert("You entered: " + Id.value)
else
alert("Would you please enter some text?")
document.location.href="ValidarEstoqueVenda.htm?Id="+Id.value+"&inQuantidade="+inQuantidade;
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/materialize.css">
<!-- Include CSS File Here -->
<script src="js/materialize.js"></script>
<title>Estoque Online - Estoque</title>
</head>
<body>
<div class="navbar-fixed">
<nav id="nav_f" class="default_color" role="navigation">
<div class="container">
<div class="nav-wrapper">
Controle de Estoque
<ul class="right hide-on-med-and-down">
<li>Estoque</li>
<%if (Usuario.getTipo() == 2){%>
<li>CadastroEstoque</li>
<li>Cadastro Tipo</li>
<li>Tipo</li>
<li>Usuario</li>
<%}%>
<li>Sair</li>
</ul>
<ul id="nav-mobile" class="side-nav">
<li>Estoque</li>
<%if (Usuario.getTipo() == 2){%>
<li>Cadastro Tipo</li>
<ul id='dropdown2' class='dropdown-content'>
<li>Usuario</li>
</ul>
<%}%>
<li>Sair</li>
</ul>
<i class="mdi-navigation-menu"></i>
</div>
</div>
</nav>
</div>
<form action="ValidarEstoque" method="get">
<table class="striped responsive-table black-text teal darken-1">
<thead>
<tr>
<th data-field="id">Id</th>
<th data-field="nome">Descricao</th>
<th data-field="email">Quantidade</th>
<th data-field="Alterar">Alterar</th>
<th data-field="Excluir">Exlcuir</th>
</tr>
</thead>
<tbody>
<tr>
<% List<produto> produtos = new ArrayList<produto>();
DAO dao = new DAO();
produtos = dao.listarEstoque();%>
<%for(produto produto : produtos){%>
<td><%=produto.getId()%></td>
<td><%=produto.getDescricao()%></td>
<td><input type="text" id="inQuantidade" name="inQuantidade" value="<%=produto.getQuantidade()%>"></td>
<% if(Usuario.getId() != 0){%>
<td>Alterar</td>
<td>Excluir</td>
<td><a class="btn waves-effect waves-light col s12" onclick="clickVender()">Vender</a></td>
<%
}
%>
</tr>
<%
}
%>
</tbody>
</table>
</form>
</body>
</html>
The last tag have the onCLick function.
Please Help me
Your code don't have id named 'Id'.
and you should don't use inline event handler.
You should refer to my code.
[HTML]
<td>
<input type="text" id="Id" name="MYID" value="my dummy Id">
</td>
<td>
<input type="text" id="inQuantidade" name="inQuantidade" value="getQuantidade">
</td>
<td><a class="govender">Vender</a></td>
[JavaScript]
function clickVender() {
var id = document.getElementById("Id");
var inQuantidade = document.getElementById("inQuantidade");
alert(id.value + ":" + inQuantidade.value);
}
document.querySelector(".govender").onclick = clickVender;
//or you can use addEventListener.
https://jsfiddle.net/nigayo/n81hd5f3/
[# additional explanation]
you can see error messages on console tab of Chrome developer tools.
https://developer.chrome.com/devtools/docs/console
Related
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
I am doing a project where the user should be able to fill up their data in an HTML table which is in a form and then submit it to a database.
In the form, the table looks like this: (top part of the 1st photo)
However, when I add a new row, I do not have the dropdown list and radio options. For the Langauge Name, I want an optional textbox field if the user selects 'Others' option.
The table now looks like this: (bottom part of the 1st photo)
HTML table before and after adding a row
I know the php code for the table is the problem but I do not know how to rectify it.
In the database, I only receive the data of the first row but NOT the subsequent rows. There should be 2 rows of entries with the same timestamp. (2nd photo)
Database entries of the HTML table
The codes are attached below:
Page5.blade.php (the javascript is in the blade.php file)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>Dynamic Table row creation and Deletion - Bootsnipp.com</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<style type="text/css">
</style>
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script type="text/javascript">
window.alert = function(){};
var defaultCSS = document.getElementById('bootstrap-css');
function changeCSS(css){
if(css) $('head > link').filter(':first').replaceWith('<link rel="stylesheet" href="'+ css +'" type="text/css" />');
else $('head > link').filter(':first').replaceWith(defaultCSS);
}
$( document ).ready(function() {
var iframe_height = parseInt($('html').height());
window.parent.postMessage( iframe_height, 'https://bootsnipp.com');
});
</script>
</head>
<body>
#extends('layout.basiclayout')
#section('content')
<p>page 5/7</p>
{!! Form::open(['url' => 'page5/submit']) !!}
<h3 style='text-decoration: underline'>LANGUAGE PROFICIENCY - </h3>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr >
<th class="text-center">#</th>
<th class="text-center">Langauge Name:</th>
<th class="text-center">Spoken Proficiency:</th>
<th class="text-center">Written Proficiency:</th>
<th class="text-center">Understanding Proficiency:</th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td>1</td>
<td><div class="form-group">
{{Form::select('Language_Name',array(
'English'=>'English',
'Tamil'=>'Tamil',
'Malay'=>'Malay',
'Chinese'=>'Chinese',
'Brumese'=>'Brumese',
'Filipino'=>'Filipino',
'Indonesian'=>'Indonesian',
'Japanese'=>'Japanese',
'Taiwanese'=>'Taiwanese',
'Thai'=>'Thai',
'Vietnamese'=>'Vietnamese',
'Others'=>'Others' ))}}
</div></td>
<td><div class="form-group">
{{Form::radio('Spoken_Proficiency','Excellent') }} Excellent <br>
{{Form::radio('Spoken_Proficiency','Good') }} Good <br>
{{Form::radio('Spoken_Proficiency','Poor') }} Poor
</div></td>
<td><div class="form-group">
{{Form::radio('Written_Proficiency','Excellent') }} Excellent <br>
{{Form::radio('Written_Proficiency','Good') }} Good <br>
{{Form::radio('Written_Proficiency','Poor') }} Poor
</div></td>
<td><div class="form-group">
{{Form::radio('Understanding_Proficiency','Excellent') }} Excellent <br>
{{Form::radio('Understanding_Proficiency','Good') }} Good <br>
{{Form::radio('Understanding_Proficiency','Poor') }} Poor
</div></td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
</div>
</div>
<a id="add_row" class="btn btn-default pull-left btn-success">Add Row</a><a id='delete_row' class="pull-right btn btn-default btn-danger">Delete Row</a>
</div>
<br>
<h4><b>Computer Knowledge</b></h4>
<div class="form-group">
{{Form::radio('Computer_Knowledge','Excellent') }} Excellent
{{Form::radio('Computer_Knowledge','Good') }} Good
{{Form::radio('Computer_Knowledge','Poor') }} Poor
</div>
<script type="text/javascript">
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='Language_Name[]"+"' type='text' class='form-control'</td><td><input name='Spoken_Proficiency[]"+"' type='text' class='form-control'></td><td><input name='Written_Proficiency[]"+"' type='text' class='form-control'></td><td><input name='Understanding_Proficiency[]"+"' type='text' class='form-control'></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
</script>
<br>
<div class="form-group">
{{Form::submit('Next Page', ['class' => 'btn btn-primary'])}}
</div>
{!! Form::close() !!}
</body>
</html>
#endsection
LanguageProficiencyController.php (I know there is a problem with the foreach loop but I do not know how to solve it)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\LanguageProficiency;
class LanguageProficiencyController extends Controller
{
public function submit(Request $request){
//language proficiency table
foreach($request->get('Language_Name') as $Language_Name) {
$LanguageProficiency = new LanguageProficiency;
foreach($request->get('Spoken_Proficiency') as $Spoken_Proficiency) {
foreach($request->get('Written_Proficiency') as $Written_Proficiency) {
foreach($request->get('Understanding_Proficiency') as $Understanding_Proficiency) {
$LanguageProficiency->Language_Name = $Language_Name;
$LanguageProficiency->Spoken_Proficiency = $Spoken_Proficiency;
$LanguageProficiency->Written_Proficiency = $Written_Proficiency;
$LanguageProficiency->Understanding_Proficiency = $Understanding_Proficiency;
$LanguageProficiency->Computer_Knowledge = $request->input('Computer_Knowledge');
$LanguageProficiency->save();
return redirect('http://formapplication.dev/page6');
}}}}
}
}
migration file.php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLanguageProficienciesTable extends Migration{
/**
* Run the migrations.
*
* #return void
*/
public function up(){
Schema::create('language_proficiencies', function (Blueprint $table){
$table->increments('id');
//create table
//$table-> string or integer('field name');
$table->string('Language_Name');
$table->string('Spoken_Proficiency');
$table->string('Written_Proficiency');
$table->string('Understanding_Proficiency');
//ADD SECOND LANGUAGE/DIALECT FIELDS HERE
$table->string('Computer_Knowledge');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down(){
Schema::dropIfExists('language_proficiencies');
}
}
I have index.jsp ,from which I am calling transaction.jsp.There is table on transaction.jsp,which i dont want to show on load of transaction.jsp,so i called a javascript method hideData() to hide the table.Now when i click on button showData on transaction.jsp,it will fetch data from database and data will be displayed in a table,which I want to display using javascript showData(),but problem is that,when i click on button,first showData() gets called and then hideData gets called as page is getting loaded again,so i am not able to diaply table on click of button.Then I tried using variable as below,but variable a is not retaining its value when it goes to hideData() after executing showData().My javascript is :
ORIGINAL POST :
<script type="text/javascript">
var a;
function hideData(){
alert("a is"+a);
alert("Inside HideData");
if(a == " ")
{
alert("Inside If");
document.getElementById('dataTable').style.display=" ";
a= " ";
}else{
alert("Inside else");
document.getElementById('dataTable').style.display="none";
a = "none";
}
}
function showData(){
document.getElementById('dataTable').style.display=" ";
a= " ";
}
</script>
Can anyone suggest,how i can achieve this.
Thanks in advance.
EDITED :
index.jsp :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello</title>
</head>
<body>
<s:form>
<h2>MI Reports Data</h2>
Transaction Data<br>
</s:form>
</body>
</html
>
transactionData.jsp :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function showData(){
document.getElementById('dataTable').style.display=" ";
}
</script>
<style type="text/css">
thead.special {
background:url('images/mcf-header-nav.jpg') no-repeat;
border: 1px solid #B0B0B0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding: 3px 12px;
margin-right: 3px 12px;
text-align: left;
}
div.statusbar {
background:url('images/mcf-header-nav.jpg') no-repeat;
color: #fff;
width:100%
font-size: 16px;
font-weight: bold;
padding: 3px 20px;
text-align: left;
}
</style>
<title>Transaction Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true">
<div class='statusbar'>Transactions Info</div>
<table border="true" id="dataTable" style="display:none">
<thead class="special">
<tr>
<td >
DateTime
</td>
<td>
channel
</td>
<td>
Transaction Type
</td>
<td>
Bic
</td>
<td>
Volume
</td>
</tr>
</thead>
<s:iterator value="listTransBean">
<tbody>
<tr>
<td>
<s:property value="dateTime"/><br/>
</td>
<td>
<s:property value="channel"/><br/>
</td>
<td>
<s:property value="transactionType"/><br/>
</td>
<td>
<s:property value="bic"/><br/>
</td>
<td>
<s:property value="volume"/><br/>
</td>
</tr>
</tbody>
</s:iterator>
</table>
<table>
<tr>
<td>
<s:submit id="submitButton" value="Show Chart" align="center" action="displayChartAction"/>
</td>
<td>
<s:submit value="Fetch Data" align="center" action="displayDataAction" onclick="showData();"/>
</td>
</tr>
</table>
</s:form>
</body>
</html>
To show data you have set display style to block..
document.getElementById('dataTable').style.display="block";
<input type="button" onclick="registerFunc()" Value="Register"></button>
<div id="demo" style="display: none">
<h2 class="mainmenu">Testing DB Connection</h2>
<table>
<tr>
<th>ID</th>
<th>Email</th>
<th>Password</th>
#foreach(var row in db.Query(userQuery))
{
<tr>
<td>#row.id</td>
<td>#row.email</td>
<td>#row.pswd</td>
</tr>
}
</table>
</div>
<p>The time is #DateTime.Now</p>
</form>
</div>
<script>
function registerFunc() {document.getElementById('demo').style.display="block";
};
</script>
function registerFunc() {document.getElementById('demo').style.display="block";
div id="demo" style="display: none"
Hi you can try out like this below. Hope this may help you out with this to get out from the challenge you may have obviously.
document.getElementById("name1").style.display= "none";
document.getElementById("name2 ").style.display = "block";
As I have mentioned in the above first thing see the id names I meant over there like name1, name2. Here name 1 will be the data which you not to show when you open a form or anything as per your requirement.name2 is the data you need to show up when you open the form etc..
First thing is you need use inline style use like this : style="display:none"; which one you need not to display by default. later use the condition in javascript wherever you need to override the condition applied using inline CSS property.
For an example:
HTML and CSS:
<table>
<tr>
<td class="text-center colspan-2 "><button onclick="saveEmp()" type="button" class="btn btn-primary btn-lg save" value="Save" id="save1">Save</button></td>
<td class="text-center colspan-2">
<button onclick="update()" type="button" class="btn btn-info btn-lg save" value="Update" id = "update1" style="display:none;" >Update</button></td>
</tr>
</table>
Javascript:
first condition:
document.getElementById("save1").style.display = "block";
document.getElementById("update1").style.display = "none";
second condition I making the second data to display and making the first data not to display:
document.getElementById("save1").style.display = "none";
document.getElementById("update1").style.display = "block";
function save() {
document.getElementById("save1").style.display = "block";
document.getElementById("update1").style.display = "none";
}
function update() {
document.getElementById("save1").style.display = "none";
document.getElementById("update1").style.display = "block";
}
And the HTML:
<table>
<tr>
<td class="text-center colspan-2 "><button onclick="saveEmp()" type="button" class="btn btn-primary btn-lg save" value="Save" id="save1">Save</button></td>
<td class="text-center colspan-2">
<button onclick="update()" type="button" class="btn btn-info btn-lg save" value="Update" id = "update1" style="display:none;" >Update</button></td>
</tr>
</table>
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 have written JSP code and I need to check white space validation, But it is not working can someone tell me the reason. While clicking submit button it must validate for white space and characters.
JSP Code
<%--
Document : LapsePeriodicFeedBack
Created on : Dec 7, 2012, 2:50:28 PM
Author : Admin
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%# page import="java.util.*" %>
<%#page import="PeriodicFeedBack.PeriodicType"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LapsePeriodicList</title>
<script>
function validateForm(){
var selectindex=document.forms["lapse"]["periodmenu"].selectedIndex;
var whitespace = new RegExp("^\w*$");
var x= document.forms["lapse"]["lapsedays"].value;
var textlength=document.forms["lapse"]["lapsedays"].length;
if(x==""){
alert("Days Cant Be Empty");
return false;
}
if(x==whitespace){
alert("White Spaces are not Allowed");
return false;
}
if(selectindex==0){
alert("Please select Days from menu");
}
}
if(x=="/\\s"){
alert('Sorry, you are not allowed to enter any spaces');
x.value=x.value.replace(/\s/g,'');
}
</script>
</head>
<body>
<form method="post" name="lapse" onsubmit="return validateForm()">
<table width="500px" border="1" align="center" style='border-collapse: collapse;font: 13px Arial, Helvetica, sans-serif;' bordercolor='#000000'>
<tr style="color:'#ffffff';background-color:#CA1619;background-repeat:repeat-x;font: 13px Arial, Helvetica, sans-serif;">
<td colspan="4" align="center">
<font color="#ffffff" > <b>Periodic Feedback List</b></font></td></tr>
<tr>
<td align="center">
Periodic Feedback Days</td>
<td align="center">
<select id="periodmenu">
<option> Select</option>
<%
PeriodicType p = new PeriodicType();
ArrayList periodicList = p.getPeriodicType();
for (int i = 0; i < periodicList.size(); i++) {%>
<option>
<% out.println(periodicList.get(i));
}%>
</option>
</select></td>
</tr>
<tr>
<td align="center">
Lapse Days </td>
<td align="center">
<p>
<input name="lapsedays" type="text" id="lapsedays" onkeyup="nospaces(this)"/></p>
<input name="Submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<p>
</p>
</body>
</html>
You can't use x==whitespace to check x against a regular expression. Use the following:
whitespace.test(x);
That'll return true or false.
In addition, you should not use new RegExp for this, you should instead use the literal operators:
var whitespace = /^\w*$/;