Results 1 to 8 of 8

Thread: javascript filter?

  1. #1
    Join Date
    May 2007
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default javascript filter?

    Hello,
    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.

    Code:
    <html>
    <head><title>Ill Form-Article Linker</title>
    <script language="JavaScript">
    function loadRefURL (){
    document.forms[0].theAddr.value = document.referrer;
    }</script>
    
    <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.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
    tempobj.selectedIndex==0)) {
    pass=false;
    break;
    }
    }
    }
    if (!pass) {
    shortFieldName=tempobj.name.substring(8,30).toUpperCase();
    alert("The "+shortFieldName+" field is a required field.");
    return false;
    } else {
    return true;
    }
    }
    </script>
    <meta name="keywords" content="">
    <meta name="Generator" content="HTMLpad">
    
    <style type="text/css">
    <!--
    .style1 {
    font-size: 18px;
    font-weight: bold;
    }
    -->
    </style>
    
    
    
    <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;
    }
    }
    </script>
    
    </head>
    
    
    <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>Parkland</option>
    
    <option>Presbyterian</option>
    <option>Houston</option>
    <option>Distance Education</option>
    </select>
    <br />
    <br />
    <b>Campus Status: </b>
    <select id="Status" name="CampusStatus">
    <option selected>Undergraduate</option>
    
    <option>Graduate</option>
    <option>Distance Education</option>
    <option>Faculty</option>
    <option>Staff</option>
    <option>Other</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 />
    <strong>
    
    <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)
    theyear+=1900
    var theday=mydate.getDay()
    var themonth=mydate.getMonth()+1
    if (themonth<10)
    themonth="0"+themonth
    var theday=mydate.getDate()
    if (theday<10)
    theday="0"+theday
    
    //////EDIT below three variable to customize the format of the date/////
    
    var displayfirst=themonth
    var displaysecond=theday
    var displaythird=theyear
    
    ////////////////////////////////////
    
    document.form1.Requested.value=displayfirst+"/"+displaysecond+"/"+displaythird
    </script>
    </body>
    </html>
    MOD EDIT: Code tags fixed and excessive white space removed.
    Last edited by jianxin9; 10-15-2007 at 07:04 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    http://www.w3schools.com/jsref/jsref_replace.asp

    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].
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2007
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    sorry, thanks

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    No problem. It's just incredibly hard to read a long block of code in the normal font.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Try this out:

    Code:
    <script type="text/javascript">
    var plus_string='bob+jane+mary+eddie'
    document.write(plus_string.replace(/\+/g, ' '))
    </script>
    I think you will get the idea.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    May 2007
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.

  7. #7
    Join Date
    May 2007
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    .replace(/[+]/g , " ")
    does the same as:

    Code:
    .replace(/\+/g, ' ')
    I figured that was the only additional code you needed. Glad you worked it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •