55 users online (1 members and 54 guests)  


  Results 1 to 4 of 4

Related

  1. I want my asp form to do 2 functions?    Forum: ASP Forum
    Replies: 2
  2. VBScript Functions    Forum: Website Scripts Forum
    Replies: 1
  3. Another Rube Goldfarb function of mine    Forum: Javascript Forum
    Replies: 4
  4. two functions    Forum: Website Scripts Forum
    Replies: 6
  1. #1
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652

    Minimizing Rube Goldfarbian functions

    Not knowing JavaScript well enough, I'm having to resort to all sorts of Rube Goldfarbian techniques to get around my ignorance. One example is:


    function email(id,d2,d1,typ,txt,subj) {
    var fil2=subj + " "
    j=fil2.length
    if (j<=1||fil2=="undefined ") { dom2=domain2 } else { dom2="" }
    if (typ==""||typ=="undefined") { typ="s" }
    ...(rest of function continues here)


    The problem, of course occurs when the calling <SCRIPT ...>('name','domain','com','s')</SCRIPT> doesn't include the last one or two ,'' parameters - even when none are required. And, apparently, unless I create even yet another variable of the same type, such as the fil2 above, the damn unused variable, containing "undefined" at some point, can't be tested for that.

    What's the knowledgeable solution to this problem?

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    At a glance, your code looks good. It seems to have checking inbuilt. How is it failing ? (maybe we need the whole sample, or the online version)

    otherwise, there is a nice trick to passing a variable amount of arguments to a JavaScript function. I am not sure if this can be applied to yours, but -

    http://developer.netscape.com/docs/examples/javascript/pass_arg.html
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    What's there does work, but is a lot of code just to discover that the subj variable wasn't passed and is, therefore, null. All that stuff was put in there, because the function wouldn't recognize if (subj=="") ... when the subj variable was null because it really had a value of "undefined" automatically inserted, I presume, by the JavaScript interpreter.

    That's kind of klunky. In almost all of the programming I've been used to, if a variable is undefined and all of a sudden shows up, it's automatically assigned a value of null or zero - JavaScript appears to not like that simple method and needs the "undefined" value to be assigned in order to gum up the works.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Yes. Javascript is lovely like that

    Once possibility is passing of an empty variable in the function -
    Code:
    <script language="JavaScript">
    
    function foo(stoat) {
    alert(stoat);
    }
    foo('');
    </script>
    this alerts a blank box. Worth a go?
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?