Announcement

Collapse
No announcement yet.

javascript in your web page, never say never

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • javascript in your web page, never say never

    Shame on all you people that know javascript and have not offered up some tidbits.

    I did want to say that I would never ever use javascript unless forced to in a web page, but I know better than to say "NEVER". I do not like the word "script" included in the same sentence with the words "web page". And I did not want to learn something new to program with, my head has enough to accomplish what needs to be done with the tools I have.


    But I came across some javascript language in learning some php programming code, why you ask? Because Powerbasic does not do CGI on a Linux OS. HINT! HINT! It is ok, none of my users use linux as a desktop anyways.

    Well my hand has now been twisted to do some javascript code because I found three little variations of similiar javascript code that you can use in your powerbasic coded cgi programs.

    I actual did not use all three javascript functions of code yet but there are three useful javascript functions I like: ALERT, CONFIRM AND PROMPT

    My php html code only uses the javascript ALERT function now, but i will surely use the CONFIRM and the PROMPT code too.
    Here it is and do not ask me what the "history.go" is, I do not know, look it up, it will fun. NOT!


    This piece of php code is some of what i am using but the functions can be easily created into powerbasic code. the web page i wrote calls itself over and over in a web page form program i wrote to send emails. the function "message" calls the other two functions "header" and "footer", so "message" is the main function for me that i call.

    the variable "$msg" in the function "message" might be assigned "you did not fill in the email field". All this is similar to MSGBOX and it might actually be the same thing except for you can have the user input a line using the PROMPT function.


    Code:
    function header()
    {
    ?>
    <HTML>
    <HEAD><TITLE>javascript to use</TITLE></HEAD>
    <BODY>
    <?php
    }
    
    function footer()
    {
    ?>
    </BODY>
    </HTML>
    <?php
    }
    
    
    function message($msg)
    {
       header();
       echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
       footer();
       exit;
    }
    this piece of code may not actually work, i just listed them for you get a look at.
    i am just bringing this to your attention so you can do a search and find out more about these three pieces of javascript functions, ALERT, CONFIRM, PROMPT.

    Code:
    <HTML>
    <HEAD><TITLE>javascript to use </TITLE></HEAD>
    <BODY>
    <script language="JavaScript">
    alert("Error: you made a error.")
    </script>
    </BODY>
    </HTML>
    
    <HTML>
    <HEAD><TITLE>javascript to use </TITLE></HEAD>
    <BODY>
    <script  language="JavaScript">
    var temp=confirm("Do you really want to do this?")
    if(temp)
    window.location="hewantstodothis.htm"
    </script>
    </BODY>
    </HTML>
    
    
    <HTML>
     <HEAD><TITLE>javascript to use </TITLE></HEAD>
     <BODY>
     <script  language="JavaScript">
    var temp=prompt("you missed this entry, enter your email address, ")
    </script>
     </BODY>
     </HTML>
    you can place some more code after the PROMPT function inside the javascript block of script such as a "IF" statement.

    I like this better than placing some stupid little red colored asterick mark you barely can see in a form, but it is ok if you do not want the user to have to run any javascript, but what freaking web page these days do not have javascript on them, HUH. This is so much better also for blind people, yes, you know exactly who i am talking about.
    Last edited by Paul Purvis; 13 Sep 2009, 02:19 AM.
    p purvis

  • #2
    Shame on all you people that know javascript and have not offered up some tidbits.
    Wow, talk about the symmetry of the universe...I never found any PowerBASIC 'tidbits' in a javascript forum.

    Amazing.
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Michael, save yourself some time and don't bother looking for it, but there might should be.

      The executable files produced by powerbasic do not run on the client's side unless you transfer the exe to the client's side then execute the exe on the clients side. By using powerbasic to create a smaller sized exes, it will be more efficient for the web connection to transfer the smaller sized exes than other exes produced by other platforms and you will also not have to worry too much about your exe program needing other installed utilities such as .NET or JAVA that may not be installed on the clients os. Just make sure the client's side is a windows os, which most often they are.
      Last edited by Paul Purvis; 14 Sep 2009, 01:03 AM.
      p purvis

      Comment


      • #4
        Originally posted by paul d purvis View Post
        Shame on all you people that know javascript and have not offered up some tidbits.
        While javascript is a neat language (and I know people that go gonzo over it) and a great teaching tool it still is almost a counterpoint to everything that PB does.

        Often website that rely on javascript become BLOATWARE that is a real PITA to work with. Many web pages that rely on js are using all sorts of libraries which all have to be downloaded.

        In fact, I have found very few instances where javascript is *required* in a webpage (client side form validation being an obvious one).

        Is it useful? Heck yeah. Having the ability to create custom event handlers etc is always useful.

        But it's still just a tool.

        Fwiw, yours is the first post I've seen here with any sort of javascript question.

        On a side note, why did you break your php code up that way? You might find it easier to use the enddoc form of the echo

        echo <<<MARKER
        this is what would print
        MARKER

        given that you had to escape the double quotes around $msg so it would print, or even output buffering (printing to a string variable)

        I usually find it easiest to include the following (as a php include) as part of the website "datafile" for every site I use php on.

        //HTML codes as variables - easier creation
        $DQ = chr(34); //double quote
        $SQ = chr(39); //single quote
        $SEMI = chr(59); //semicolon
        $SPC = chr(32); //space

        Similarities to the PB constants completely intentional <grin>.

        Real easy then to build complex strings if I don't want to use enddoc.
        John,
        --------------------------------
        John Strasser
        Phone: 480 - 273 - 8798

        Comment


        • #5
          A little piece of advise, do not use JavaScript to verify fields instead, rely on PHP, after you POST you verify it, for example:

          PHP Code:

          $user_name 
          $_POST["UserName"]; // In this example, UserName is the name of the EDITBOX on your HTML FORM

          if (empty($user_name)) {

             echo 
          "Please enter User Name";


          The code above is a very bare-bones sample of course, but an effective way to validate info.
          Ivan

          Uncle Droid (Android Apps)

          Comment


          • #6
            Hi Ivan,

            Actually, you would be better served using BOTH - javascript in the page to do an initial check (valid email address, all fields filled in etc) and then on the server to validate the data.

            JS
            John,
            --------------------------------
            John Strasser
            Phone: 480 - 273 - 8798

            Comment


            • #7
              Originally posted by John Strasser View Post
              Hi Ivan,

              Actually, you would be better served using BOTH - javascript in the page to do an initial check (valid email address, all fields filled in etc) and then on the server to validate the data.

              JS
              Yes I agree, but I believe is a personal preference, I just let PHP do almost everything.
              Ivan

              Uncle Droid (Android Apps)

              Comment


              • #8
                For me, javascript is indispensable.

                My general web philosophy is to do anything that can be done on the client side (i.e. validations, computations, dynamic cosmetic effects, etc), and just do data manipulation on the server. Of course, this is dependant on the dynamic of the web site you are developing but it's my rule of thumb.

                Comment


                • #9
                  Well i just could not resist yanking MCM's chain a little bit, of course there is no way to run a exe on the clients side without some kind of script.
                  I know more about javascript than C. Trust me, that ain't much.

                  The code was in PHP becuase of the linux server, but i would believe most people could follow the javascript example without much effort. One of the main reasons i wanted to share that, is because many times lately i have had to fill out something on a webform and not filling out the form to the servers satisfaction it kicked back the form and i could not see easily the problem to fix. My eyes are getting weaker, dimmer and fuzzier. I also do not lilke to look around for over ten seconds to find what i did wrong. I probably am not the only one using large screens, with tiny print or small screens with tinyer print.

                  In windows 2000 pro when you log on, there are two fields, a username and a password. Over two months ago, i started making locking down the computers, making it where you have to login from a boot or a lockout from a screen saver. One person complained because they could not login.
                  The username they where trying to login was the administrator, not the username. Before, the computer would login automatically after a boot.
                  So there it was just those two freaking fields. On windows, you have to type in the username if it was not the last logged in username you wanted to use. So it just goes to show you how something so easy can be so fustrating to somebody. And i specially do not want to fustrate any of my customers.

                  I just thought those like me would like to have another way to do things on their webpages they are writing without having to be a knowledgable javascript programmer. Maybe those short pieces of code can save somebody a lot of time, then again maybe not.

                  Thanks for the responses and maybe in the future, i will have some more javascript tidbit pieces. If you want to be the best learn from the best.

                  Thank God I have this forum to use.
                  p purvis

                  Comment


                  • #10
                    The executable files produced by powerbasic do not run on the client's side unless you transfer the exe to the client's side then execute the exe on the clients side.
                    I call that "making a sale."
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Amazing things can be done in Javascript.
                      Like a NES emulator:

                      http://benfirshman.com/projects/jsnes/

                      Bye!
                      -- The universe tends toward maximum irony. Don't push it.

                      File Extension Seeker - Metasearch engine for file extensions / file types
                      Online TrID file identifier | TrIDLib - Identify thousands of file formats

                      Comment


                      • #12
                        It's a great language. Simple to use and work with.

                        Usually I'll have the code on a webpage (form) do something with the data and then spit it over to a php script for further processing.

                        As always, the biggest issue is what the program is to be used for. General business type websites (the kind where you advertise your business, etc) generally *need* very little.

                        Designing applications to run inside a browser would be a different animal entirely.

                        Debugging tip: when pulling data from a form watch the variable type. I once spent 2 hours (not too long ago either I'm afraid to admit) tracking down a bug where the integer value 0 was confused with the string character 0

                        JS
                        John,
                        --------------------------------
                        John Strasser
                        Phone: 480 - 273 - 8798

                        Comment

                        Working...
                        X