SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Runcorn
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question I get an 'Object Expected' Error ?

    Hi All,

    I have attached the code that I have been working on and I have come to
    a sticking point. I cannot find where I have where the 'Object Expected' is?.

    I would appreciate help on this problem, please?

    p.s. Sorry, but unfortunately the code 'justifies to the left automatically, I hope you will be able to reformat it with the indents?

    <HTML>
    <HEAD>
    <TITLE> Function Prog</TITLE>
    <SCRIPT>

    function aVowel(aCharacter)
    {
    return ((aCharacter == 'a') || (aCharacter == 'A') ||
    (aCharacter == 'e') || (aCharacter == 'E') ||
    (aCharacter == 'i') || (aCharacter == 'I') ||
    (aCharacter == 'o') || (aCharacter == 'O') ||
    (aCharacter == 'u') || (aCharacter == 'U'))
    };


    function loseVowels(aString)
    /********************************************************/
    /*This function takes a string as its argument and */
    /*returns, as its result, a new string which is similar */
    /*to the argument string except that all the vowels */
    /*have been removed. */
    /********************************************************/
    {
    outPutString = (''); //local variable to hold the new string

    for (var count = 0; count < aString.length; count = count + 1)
    {
    outPutString = aString.charAt(count);
    if (!aVowel(aString.charAt(count)))
    {
    return outPutString;
    }
    }
    };


    /*The code below calls the function 'loseVowels()' */
    /*with an argument which will assign the result to a */
    /*variable which in turn will be displayed in a 'alert' box */


    var joker

    joker = outPutString('Hello there, this is the joker')

    /* Code to create a form with a button which produces an alert box */

    </SCRIPT>
    </HEAD>
    <BODY>

    <FORM NAME = "Joker">

    <INPUT TYPE = "button"
    VALUE = "Press Me"
    ONCLICK = "window.alert(joker);">

    </FORM>
    </BODY>
    </HTML>

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is where you try to assign outPutString() to the variable joker, since outPutString is a variable itself, not a function.

  3. #3
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Runcorn
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question I get an 'Object Expected' Error?

    Quote Originally Posted by JVLB
    The problem is where you try to assign outPutString() to the variable joker, since outPutString is a variable itself, not a function.
    Hi JVLB,
    Thank you for your reply.
    I have altered the code a little and I now the 'Alert' displays a result
    but it only shows the first letter 'H' and I want it to display the full
    string except the 'vowels'?
    Do you know where I am going wrong?

    Regards
    Gerryw1

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you need to look into for your purposes is Regular Expressions. Consider the following:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Strip Vowels with RegExp</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    html,body{height:100%;}
    </style>
    <script type="text/javascript">
    function stripVow(){
    var targ_str="The quick brown fox jumped over lazy dogs. THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS.";
    var fin_str=/[^aeiouAEIOU]/g;
    var result=targ_str.match(fin_str);
    var ln=result.length;
    var fin_res="";
    for(var i=0;i<ln;i++){
    fin_res+=result[i];
    }
    alert(fin_res);
    }
    </script>
    </head>
    <body onclick="stripVow();">

    </body>
    </html>


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
  •