View Full Version : javascript filter?

10-15-2007, 06:47 PM
Is there a way I can add a filter to this form? I am pulling info from a referring URL and popping it into form text boxes. Between the words in the referring URL are "+" signs, and I just want a space instead of a plus sign in the form results. Any help is greatly appreciated.

<head><title>Ill Form-Article Linker</title>
<script language="JavaScript">
function loadRefURL (){
document.forms[0].theAddr.value = document.referrer;

<script language="JavaScript">
// JavaScript Document

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: wsabstract.com | http://www.wsabstract.com */
function checkrequired(which) {
var pass=true;
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.selectedIndex==0)) {
if (!pass) {
alert("The "+shortFieldName+" field is a required field.");
return false;
} else {
return true;
<meta name="keywords" content="">
<meta name="Generator" content="HTMLpad">

<style type="text/css">
.style1 {
font-size: 18px;
font-weight: bold;

<script type="text/javascript">
function getQueryValue(name) {
var match = (new RegExp('[?&;]' + name + '=([^&;#]*)')).exec(document.referrer);

return match ? unescape(match[1]) : null;

function populateFields() {
var controls = document.forms.form1.elements,
fieldMap = {ArticleTitle: 'atitle', JournalTitle: 'title', ISSN: 'issn', DatePub: 'date',
StartPage: 'spage', Volume: 'volume', Issue: 'issue',
AuthorLastName: 'aulast', AuthorFirstName: 'aufirst', ArticleAuthor: 'author', Authors: 'authors'};

for (var i = 0, n = controls.length; i < n; ++i) {
var value = getQueryValue(fieldMap[controls[i].name]);
if (value) controls[i].value = value;


<body onLoad="populateFields(); loadRefURL()">

<form method=post action=http://ezproxy.twu.edu:2065/cgi-bin/aspmail.asp id=form1 name=form1 onSubmit="return checkrequired(this)">

<input type=hidden name=sendername value="Automailer">
<input type=hidden name=subject value="Request for interlibrary loan (generated by Article Linker results page)">
<input type=hidden name=recipientname value="ILL">
<input type=hidden name=recipientmail value="ill@mail.twu.edu">
<input type=hidden name=redirect value=http://ezproxy.twu.edu:2065/library/>
<input type=hidden name=userinfo value="on">

<span class="style1">Interlibrary Loan request form--TWU Libraries</span>

<br />
<br />

<b>Patron Last Name, First Name: (required field)</b>
<input type="text" name="required Name" size="50" /><br><br>
<b>Student ID: (required field)</b>
<input type="text" name="required ID#SSN" size="50" /><br><br>
<b>Patron Address: (required field)</b> <br />

<textarea name="required Address:" rows="3" cols="20" wrap="virtual"></textarea><br><br>

<b>Patron Email Address (required field): </b>
<input type="text" name="required Email Address" size="50"/><br><br>

<b>Phone: </b>
<input type="text" name="Phone" size="50"/><br><br>

<b>Pickup Location: </b>
<select id="Department" name="Campus">
<option selected>Denton</option>

<option>Distance Education</option>
<br />
<br />
<b>Campus Status: </b>
<select id="Status" name="CampusStatus">
<option selected>Undergraduate</option>

<option>Distance Education</option>
</select><br /><br />
<b>Other Comments (optional): </b> <br />

<textarea name="Comments:" rows="3" cols="40" wrap="virtual"></textarea><br><br>

<strong>Please scroll down and submit the form. Do not edit any information below this point.</strong>

<br /><br />

<label>Journal Title:</label> <input name="JournalTitle" type="text" /><br /><br />
<label>ISSN:</label> <input name="ISSN" type="text" /><br /><br />
<label>Volume: </label><input name="Volume" type="text" /><br /><br />

<label>Issue: </label><input name="Issue" type="text" /><br /><br />
<label>Date: </label><input name="DatePub" type="text" /> <br /><br />

<label>Article Title: </label><input name="ArticleTitle" type="text" /><br /><br />
<label>Author: </label><input name="ArticleAuthor" type="text" /><br /><br />
<label>Author Last Name: </label><input name="AuthorLastName" type="text" /><br /><br />

<label>Author First Name: </label><input name="AuthorFirstName" type="text" /><br /><br />

<label>Authors: <input name="Authors" type="text" size="50" / ></label><br /><br />
<label>Start Page: <input name="StartPage" type="text" size="50" /></label></strong><br /><br />

<strong>Date Requested: </strong><input type="text" name="Requested" size=11>
<br /><br />
<strong>Page URL: </strong><input type=text name="theAddr" size=50 /><br /><br />
<input type="submit" value="submit">

</form> <script>

/*Current date in form credit:
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!

var mydate=new Date()
var theyear=mydate.getYear()
if (theyear < 1000)
var theday=mydate.getDay()
var themonth=mydate.getMonth()+1
if (themonth<10)
var theday=mydate.getDate()
if (theday<10)

//////EDIT below three variable to customize the format of the date/////

var displayfirst=themonth
var displaysecond=theday
var displaythird=theyear



MOD EDIT: Code tags fixed and excessive white space removed.

10-15-2007, 06:55 PM

And why do you have extra <br> tags then html close tags at the end of your code?

Note that for codes on this board (and most), unlike html, it isn't <code>, but [code].

10-15-2007, 07:12 PM
sorry, thanks

10-15-2007, 07:21 PM
No problem. It's just incredibly hard to read a long block of code in the normal font.

10-16-2007, 07:53 AM
Try this out:

<script type="text/javascript">
var plus_string='bob+jane+mary+eddie'
document.write(plus_string.replace(/\+/g, ' '))

I think you will get the idea.

10-16-2007, 05:16 PM
Hi John,
Thanks a lot for the response I do appreciate it. I apologize for what I am sure is a stupid question, but if the referring url information is always different, is it still possible to use a code like that since there is no way to predict what will be placed in the form text boxes via the referring url? I don't actually know in advance what will be placed in the boxes, I only know that the words will separated by "+" signs.

10-16-2007, 05:58 PM
I was able to get a solve for the problem. It is:

replace the:
return match ? unescape(match[1]) : null;
with something like:
return (match) ? unescape(match[1]).replace(/[+]/g , " ") : null;

That did the trick! Thanks to all who replied--I do appreciate it.

10-16-2007, 09:04 PM
.replace(/[+]/g , " ")

does the same as:

.replace(/\+/g, ' ')

I figured that was the only additional code you needed. Glad you worked it out.