I have an application that converts all returns, spaces and tabs with ',' and trims the ends for the use in SQL statements.
I also have a demo area that does the same, but limits the SQL to 5 criterias.
ie. Where num in ('101','102','150','243','323')
Here is the demo link-> http://www.datapaste.com/pub/demo.php
My problem is that my limit is set to 5 and when you type less than 5 (criterias or words) for example, the result looks something like this->
cow','bear','sheep ->which is right
but when you type more than 5 criterias, the result looks something like this->
cow','bear','sheep','dog','goat' -> which is wrong because it has a single quote appended to the end.
There has to be an easier (simpler) way to do this without all javascript. I'm using php to protect my application from being downloaded to a computer and having the ability to run it without limitations. Really I would like to have as much server side as possible. it's kind of ugly, but I'm new at this and need it working.
Any ideas would be appreciated.
Thanks, tav
Here is my code->
<?php
session_start();
require_once ( "Sajax.php" ); //download this from www.modernmethod.com/sajax
sajax_init();
sajax_export( "parse_spaces" );
sajax_handle_client_request();
function parse_spaces ( $str )
{
$find = array ("\r\n", "\n", "\',\'", "\'", " ", "','", "','','", "','','", "','','", "','','");
$replace = "','";
return trim( str_replace( $find, $replace, $str ), "','");
}
?>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<!--[if !mso]>
<style>
v\:* { behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
</style>
<![endif]--><!--[if gte mso 9]>
<xml><o:shapedefaults v:ext="edit" spidmax="1027"/>
</xml><![endif]-->
<i><title>DataPaste __bringing simplicity to the users...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="File-List" href="demoworkorder_files/filelist.xml">
<link href="main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="scrollblue.css">
</head>
<body bgcolor="#999999" background="patch_purple.gif" text="#FFFFFF" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="word-spacing: 0; margin-top: 0; margin-bottom: 0; text-align:left">
<script>
function passText(str) {
document.yourform.select.value = "Where WORKORDER.WONUM in ('" + str + "')";
}
function passText2(str) {
document.yourform.select.value = "Where WORKORDER.LEADCRAFT in ('" + str + "')";
}
function passText3(str) {
document.yourform.select.value = "Where WORKORDER.STATUS in ('" + str + "')";
}
function passText4(str) {
document.yourform.select.value = "Where PLEASE PURCHASE A MEMBERSHIP! in ('" + str + "')";
}
</script>
<script>
<? sajax_show_javascript(); ?>
function getcleanseddata() {
var elem=document.getElementById("user");
x_parse_spaces(elem.innerHTML, toggle); //or elem.value if a field
}
//function toggle(val) {
// var elem=document.getElementById("user");
// elem.innerHTML = val; // or elem.value if a field
//}
//function toggle(str) {
// var elem=document.getElementById("user");
// elem.innerHTML = str; // or elem.value if a field
// document.getElementById('cnt').innerHTML = str.length
//}
//works//function toggle(strVal) {
// var elem=document.getElementById("user");
// var strArray = strVal.split (",");
// var intLimit = 5;
// strArray = strArray.slice( 0,intLimit );
// elem.innerHTML = strArray; // or elem.value if a field
// document.getElementById('cnt').innerHTML = strArray.length;
//}
function toggle(strVal) {
var elem=document.getElementById("user");
var strArray = strVal.split (",");
var intLimit = 5;
strArray = strArray.slice( 0,intLimit );
elem.innerHTML = strArray; // or elem.value if a field
document.getElementById('cnt').innerHTML = strArray.length;
}
// function doCoolThings( ta ) {
// ta.value = convertSpaces( ta.value );
// var aryItems = ta.value.split( "','" );
// aryItems = aryItems.slice( 0, intLimit );
// ta.value = aryItems.join( "','" );
// countWords(ta.value);
// function toggle(strVal){
// var elem=document.getElementById("user");
// var strArray = strVal.split ("','");
// document.getElementById('cnt').innerHTML = strArray.length;
// }
</script>
<!-- BEGIN FIRST FORM -->
<form name="myform">
<!-- BEGIN TEXT AREA 1 -->
<textarea name="user" rows="10" cols="30" onBlur="this.value = getcleanseddata();"></textarea>
<!-- END TEXT AREA 1 -->
<div align="left"><font color="#FFFFFF">
Record count is <SPAN id=cnt>0</SPAN></font></div>
<P></P>
<P></P>
<!-- CONVERT BUTTON 1 -->
<input type=button value="WoNumber " onClick="parent.passText(this.form.user.value);"><i>
<input type=button value="LeadCraft " onClick="parent.passText2(this.form.user.value);"> </i>
<!-- CONVERT BUTTON 2 -->
<i>
<input type=button value="Status " onClick="parent.passText3(this.form.user.value);"></i>
<i><input type=button value="Wo Type " onClick="parent.passText4(this.form.user.value);"></i>
<!-- RESET BUTTON -->
<input type="reset" value="Reset" name="B1">
</form>
<!-- END FIRST FORM -->
<!-- START COPY TO CLIPBOARD -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
// End -->
</script>
<!-- END COPY TO CLIPBOARD -->
<form name="yourform">
<textarea name="select" rows="10" cols="30" ></textarea>
<input onclick="copyit('yourform.select')" type="button" value="Press to Copy the Text" name="cpy">
<input type="reset" value="Reset" name="B1">
</i>
</body>
</html>