SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict lostatsea's Avatar
    Join Date
    Oct 2005
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing white spaces between words Javascript/ColdFusion MX 7

    Hello everyone

    I have been doing a bit of searching and I think I may be typing in the wrong keywords to find my solution. I am VERY new with Javascript.

    I am having an issue with spaces in between text coming from Oracle 9i.

    I am using CFMX7, DW8 too.

    Does anyone know how I can set this script up to remove the extra spaces from between words in my PROJECT_NAME field?

    Example: Project Name will have spaces in their names like - My Zone. I get no errors if I just put in one word into this field, but Javascript does not like the two words in the same field.

    This script works well for my purposes except for those darn spaces in between the project names.

    Thanks for any help.

    LAS

    -------------------

    <cfquery name="getprojectname" datasource="#myzone#" username="#username#" password="#password#">
    SELECT DISTINCT PROJECT_NAME, PROJECT_NUMBER
    FROM PROJECT
    where PROJECT_DETAILS_ID=PROJECT_DETAILS_ID
    ORDER BY PROJECT_NAME
    </cfquery>

    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" href="frontstyleviews.css" />
    <title>Add New Title</title>
    <script type="text/javascript">
    <!--
    // For each project name, create an array to hold the project numbers.
    // Each project name array will be identified
    <cfoutput query="getprojectname" group="PROJECT_NAME">
    // Create the array
    ProjectNameArray#PROJECT_NAME# = new Array();
    <cfset i = 0>
    // Populate the array
    <cfoutput>
    <cfset i = i + 1>
    ProjectNameArray#PROJECT_NAME#[#i#] = #PROJECT_NUMBER#;
    </cfoutput>
    </cfoutput>

    // Function to populate the project number for the project name selected
    function PopulateProjectNumber() {
    // Only process the function if the first item is not selected.
    if (document.ProjectForm.PROJECT_NAME.selectedIndex != 0) {
    // Find the project name
    var ThisProject = document.ProjectForm.PROJECT_NAME[document.ProjectForm.PROJECT_NAME.selectedIndex].value;
    // Set the length of the project number drop down equal to the length of the project name's array
    document.ProjectForm.PROJECT_NUMBER.length = eval("ProjectNameArray" + ThisProject + ".length");
    // Put 'Select' as the first option in the project number drop-down
    document.ProjectForm.PROJECT_NUMBER[0].value = "";
    document.ProjectForm.PROJECT_NUMBER[0].text = "Select";
    document.ProjectForm.PROJECT_NUMBER[0].selected = true;
    // Loop through the project name's array and populate the project number drop down.
    for (i=1; i<eval("ProjectNameArray" + ThisProject + ".length"); i++) {
    document.ProjectForm.PROJECT_NUMBER[i].value = eval("ProjectNameArray" + ThisProject + "[i]");
    document.ProjectForm.PROJECT_NUMBER[i].text = eval("ProjectNameArray" + ThisProject + "[i]");
    }
    }
    }


    //-->
    </script>
    </head>
    <body>
    <!---Page Title--->
    <div class="title">JUST A TITLE PAGE</div>

    <div class="bodymiddleleft">
    <form name="ProjectForm">
    <p>
    <table border="0">
    <tr>
    <td><b>Project Name</b></td>
    <td><b>Project Number</b></td>
    </tr>
    <tr>
    <td>
    <select name="PROJECT_NAME" onChange="PopulateProjectNumber();">
    <option value="0">Select Project Name
    <cfoutput query="getprojectname">
    <option value="#getprojectname.PROJECT_NAME#">#getprojectname.PROJECT_NAME#</option>
    </cfoutput>
    </select>
    </td>
    <td>
    <select name="PROJECT_NUMBER" size="1">
    <option value="0">Select Project Number
    <cfoutput query="getprojectname">
    <option value="#getprojectname.PROJECT_NUMBER#">#getprojectname.PROJECT_NUMBER#</option>
    </cfoutput>
    </select>
    </td>
    </tr>
    </table>
    </form>
    </div>
    </body>
    </html>

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see your using your project name to name/identify form elements created using the same name.

    if you want to remove all spaces within the content, just use a replace function. In Javascript you can use

    var test = 'test with spaces a a a a a a ';
    test = test.replace(' ','');

    which will return

    testwithspacesaaaaaa

    As for CF, i'm not sure, but I am sure that there is a function to manipulate the data your outputting.


  3. #3
    SitePoint Addict lostatsea's Avatar
    Join Date
    Oct 2005
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much for responding. As you can tell I am not javascript person.

    Quote Originally Posted by gRoberts View Post
    I see your using your project name to name/identify form elements created using the same name.

    Should I not be using the same names?

    if you want to remove all spaces within the content, just use a replace function. In Javascript you can use

    var test = 'test with spaces a a a a a a ';
    test = test.replace(' ','');

    which will return

    testwithspacesaaaaaa

    As for CF, i'm not sure, but I am sure that there is a function to manipulate the data your outputting.


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
  •