SitePoint Sponsor

User Tag List

View Poll Results: What server side language(s) do you prefer for working with Javascript?

Voters
8. You may not vote on this poll
  • Cold Fusion

    2 25.00%
  • PHP

    6 75.00%
  • ASP

    1 12.50%
  • JSP

    0 0%
  • Perl

    0 0%
  • Other

    0 0%
Multiple Choice Poll.
Results 1 to 8 of 8

Thread: "ListLen()"

  1. #1
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "ListLen()"

    I'm writing a very powerful search engine.. the boolean operators are not actual words but are easy to remember...

    QAND,QOR,QNOT... My problem is this, the search query is pretty heavy, so I want to limit the number of words / phrases to 5 and pop up an alert if the number is greater than 5...

    word QAND phrase QAND idea QNOT microsoft would pass word QAND MS QOR Micro QNOT Site QAND Cool QOR Wow would not pass...

    I know how the script needs to be written just don't know how to write it...

    The boolean operators will only work surrounded with a space on each side.. so what I need the JS to do (Netscape AND IE compatibility here) is replace each boolean operator with a comma (,) or whatever... The $ appears nowhere in the Bible which is my search base so that would be a good delimiter.. Anyway it needs to make a list of it and then ListLen() it.. If JS does not have a listlen function, what that is, is it counts the number of elements in a list (at least in cold fusion)... If the number is greater than 5, alert, and then abort the form submit, if not, go on...

    Any help very greatly appreciated,
    Tony Hicks

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    javascript, jscript, echmascript/vbscript are all client side languages and have nothing todo with programming with a server side language.

    I'm not exactly sure what you need by the above as most of what you mentioned should be done behind the scenes with a server side language ie php, jsp, asp etc.

    As for counting the length of an array it is extremely simple.

    PHP Code:
    <script type="text/javascript">
    <!--
      var 
    i=0;
      
    myArray = new Array();

      
    myArray[i++] = '0';
      
    myArray[i++] = '1';
      
    myArray[i++] = '2';
      
    myArray[i++] = '3';
      
    myArray[i++] = '4';
      
    myArray[i++] = '5';
      
    myArray[i++] = '6';
      
    myArray[i++] = '7';
      
    myArray[i++] = '8';
      
    myArray[i++] = '9';

      function 
    countArraySize(arrayName)
      {
        
    alert(arrayName.length);
        return 
    arrayName.length;
      }

      
    countArraySize(myArray);
    // -->
    </script> 

  3. #3
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Q

    Ok.. could do it server side but JS will handle it client side and save my server some processing time.. Maybe if I write it in CF, you'll grok my needs...

    // Setting the search variable here, but it would actually come from a text field...
    <CFSET sVar="God said QAND Jesus QOR Messiah QNOT Satan QOR Michael QAND the angel">

    (The syntax of the Replace/ReplaceNoCase Fuctions... are (String, Substring1, Substring2, ONE[Replace first instance]/ALL[Replace all instances]))

    <CFSET sVar=ReplaceNoCase(svar," QAND " , "," , "ALL")>
    <CFSET sVar=ReplaceNoCase(svar," QOR " , "," , "ALL")>
    <CFSET sVar=ReplaceNoCase(svar," QNOT " , "," , "ALL")>

    <CFIF ListLen(sVar) gt 5>
    Error! Error! To many words or phrases.
    <CFELSE>
    Process Search Query
    </CFIF>

    Does this help?

    Tony

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use ASP (using VBScript) because it happens to be what I prefer to develop in, and JavaScript because it's a cross-platform client-side scripting language.

    There is no real link between server-side scripting language and client-side scripting language - they are separate and distinct, serving two completely different purposes, and should be chosen independently on their separate merits (since there are no joint merits to consider - any combination can be made to work together).
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  5. #5
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Very True...

    Very True... but for isntance with CF, if you are working with variabes and you want to display a pound sign, you have to double it ##.. And then it displays as a single on a webpage..

    And php resembles javascript somewhat so that creates some problems in that it can be quite hard to read..

    There are things to consider here

    Tony

  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it may be hard because your not used to it or you have made the code unclear in the first place. Anyway i'm not too sure about cf but that kind of problem you seem to have come accross is very rare,

    The closest problem you may have to that is escaping characters. But thats in most languages anyway.

  7. #7
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erk, never came across it.. not yet, but all I was saying is that each language can counteract with JS in some way..

    Tony

  8. #8
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's not even that tho. Theres clientside and theres server side, now a language that does come close to or does in effect combine clientside to the serverside is asp.net and as far as im aware no other language does.


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
  •