www.webdeveloper.com
Page 2 of 15 FirstFirst 123412 ... LastLast
Results 16 to 30 of 221

Thread: Here are 2 prototype-functions I created.

  1. #16
    Join Date
    Oct 2004
    Location
    Australia
    Posts
    76
    oh yeah, i have a few protoype scripts, im not the best at javascript, i think im better at CSS. One of my prototypes includes a navigation bar that is static at the top of the page, it allows access to mail box and stuff like that, its half finished though.

  2. #17
    Join Date
    Feb 2005
    Location
    USA
    Posts
    1,534
    hmmm... robo_neojetsam probably misunderstands the meaning of prototype...

  3. #18
    Join Date
    Oct 2004
    Location
    Australia
    Posts
    76
    i guess it really isnt a prototype, but who cares.

    Heres a little something that i just wrote up, its very simple, when an Javascript error is found, it alerts the user and asks to block it.

    Heres the code itself (without any errors):
    HTML Code:
    <script>
    function checkerror(){
    alert('A Javascript Error has been found.');
    var answer=confirm("Do you wish to block this error?")
    if (answer) {
    return true;
    alert('The Javascript Error has blocked.');
    }
    else {
    alert('The Javascript Error on this page has not been blocked.');
    }
    }
    window.onerror = checkerror;
    </script>
    And heres the error part (which i am sure most of you can make REAL quick )
    HTML Code:
    <script>
    ERROR
    function makeerror() {
    dfsfsdfsdfsdf
    }
    </script>
    
    
    <a onclick="javascript:makeerror()" href="http://www.google.com">Make error and redirect</a>
    i think its cool...

  4. #19
    Join Date
    Feb 2005
    Location
    USA
    Posts
    1,534
    One problem with that, this part should be:
    Code:
    if (answer) {
    alert('The Javascript Error has blocked.');
    return true;
    }
    if you want to actually get the alert,

    If i were to use a code like this i would rather:
    Code:
    <script>window.onerror=Function("return true")</script>
    because the only person who actually cares where the error occurs is the person debugging it. The user is likely to not care about the details of the error and if it is possible to pass it off pretending no error occured then that is the best.

  5. #20
    Join Date
    Oct 2004
    Location
    Australia
    Posts
    76
    i think the user should interact with the website as much as possible, to keep them entertained, this code could be usefull if the site has a special 'place' where the member can upload HTML and Javascript to make their own page about them etc. Another use for this code could be a HTML/Javascript test area. i think the code is ok, after all im a 13 year old Javascript beginer.

  6. #21
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You can probably send a request to Google's translation service to translate a language, and then return the result. That seems a bit impractical, though it is the only way to get a good translation. (Since the translator takes grammar into account.)

    Ultimater, what's a "hugh" number? Do you mean "huge," or is it something that I just don't know about? If you're saying what I think you're saying, how are you going about it? I would think you'd take the large scientifc notation that a calculation outputs, divide it into as many parts as necessary, and then return a string result with the answer?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  7. #22
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Here's one. Multi-dimensional array searching.

    ArraytoSearch.search (String search term [, Boolean exact match])

    Note: "ArraytoSearch" is an array variable. String search term is what you want to find in that array. Boolean exact match can be set to true or false. If you want to find an exact match, you can omit this argument or send it as false. If you want to find an instance, you can send this argument as true.


    Code:
    Array.prototype.search = function(s,q){
     var len = this.length;
      for(var i=0; i<len; i++){
       if(this[i].constructor == Array){
        if(this[i].search(s,q)){
          return true;
          break;
        }
       } else {
        if(q){
         if(this[i].indexOf(s) != -1){
            return true;
            break;
         }
        } else {
         if(this[i]==s){
          return true;
          break;
         }
        }
       }
      }
     return false;
    }
    Some example uses.

    Code:
    var ary = [
               [
                ["animal","maniac"],["canibal","twix"]
               ],
               [
                ["chump","zoo"],["sam","potato"]
               ],
               [
                ["chimpanzee", "chipmunks"],["karaoke", "pen"]
               ],
               [
                ["geometry", "logic"],["Texas", "California"]
               ]];
    
    if(ary.search("geo",true)){
     document.write ('Found<br>');
    } else {
     document.write ('Not found<br>');
    }
    
    if(ary.search("geo")){
     document.write ('Found<br>');
    } else {
     document.write ('Not found<br>');
    }
    
    if(ary.search("chump")){
     document.write ('Found<br>');
    } else {
     document.write ('Not found<br>');
    }
    Code:
    var ary = ["geometry", "logic", "Texas"];
    
    if(ary.search("geo")){
     document.write ('Found<br>');
    } else {
     document.write ('Not found<br>');
    }
    
    if(ary.search("geo",true)){
     document.write ('Found<br>');
    } else {
     document.write ('Not found<br>');
    }
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  8. #23
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    Quote Originally Posted by Jona

    Ultimater, what's a "hugh" number? Do you mean "huge," or is it something that I just don't know about? If you're saying what I think you're saying, how are you going about it? I would think you'd take the large scientifc notation that a calculation outputs, divide it into as many parts as necessary, and then return a string result with the answer?
    Yup, I was saying what you think I was saying.
    What I mean by "hugh" number is any number that becomes too big and gets transformed into Scientic Notation by JavaScript.

    When written in Scientic Notation, the number is only approximiate.
    Thus, I can't rely on JavaScript's "built-in" adding and subtracting operators
    with regard to big numbers.

    That's the reason why there is a need to create such a function -- to handle such matters.

  9. #24
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    Reminder!
    This thread is to be used for prototype-functions only!
    (The big numbers issue got a bit off-topic!)

    Let's keep this thread aimed at the submitting of finished prototype-functions rather than discussing their development.

  10. #25
    Join Date
    Jul 2004
    Location
    Canada, eh
    Posts
    784
    It wasn't really off-topic; in the biginteger code, the functions are turned into string-prototypes.
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  11. #26
    Join Date
    Oct 2004
    Location
    Australia
    Posts
    76
    oh one thing with the calculator, add a script to block errors, because if you enter and invalid character it comes up with an JS Error.

  12. #27
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    Quote Originally Posted by HaganeNoKokoro
    It wasn't really off-topic; in the biginteger code, the functions are turned into string-prototypes.
    It got a bit off topic by having to discuss the creation of a function which wasn't created yet.
    The creating of the actual function should've been done elsewhere in a different thread similar to this:
    Subtracting Hugh Hex Numbers

    This thread should be used as a place to post prototype-functions which are complete, long finished, and tested so that there are no attachments or codes that are bad. Vistors to this thread should be able to browse through this thread with ease and not have to test bad codes or piece-together different scripts which are all of the place.
    Last edited by Ultimater; 04-10-2005 at 02:04 AM.

  13. #28
    Join Date
    Jul 2004
    Location
    Canada, eh
    Posts
    784
    ah, i didn't know about that thread
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  14. #29
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Would you like me to split off the posts in this thread and append them to that thread, Ultimater?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  15. #30
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

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



Recent Articles