Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: sample code for javascript beginners  (Read 8605 times)

0 Members and 1 Guest are viewing this topic.

lina19

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    sample code for javascript beginners
    « on: January 07, 2012, 06:07:36 AM »


    <html>

    <script type="text/javascript">
    function login()
    {

       var username=document.getElementById("username").value;
       alert(username);

    }
    </script>
       
    <form id="loginpage" name="loginpage" method="post" action="#">

       <table border=1>
          <tr>
             <td>Username :</td>
             <td><input type="text" name="username" id="username"></td>
          </tr>
       
          <tr>
             <td>Password   :</td>
             <td><input type="password" name="password" id="password"></td>
          </tr>
       
          <tr>
             <td><input type="submit" name="but_ok" id="but_ok" value="ok" onclick="login()"/></td>
          </tr>

          
       </table>
    </form>
    </html>
       

    Veltas



      Intermediate

      Thanked: 7
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Linux variant
    Re: sample code for javascript beginners
    « Reply #1 on: January 08, 2012, 05:59:56 PM »
    No <head>, nor <body>?

    Linux711



      Mentor

      Thanked: 59
      • Yes
      • Programming Blog
    • Certifications: List
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: sample code for javascript beginners
    « Reply #2 on: January 08, 2012, 06:23:30 PM »
    This is somewhat unrelated, but I think there should be a sub-forum for code snippets.
    YouTube

    "Genius is persistence, not brain power." - Me

    "Insomnia is just a byproduct of, "It can't be done"" - LaVolpe

    Raptor

    • Guest
    Re: sample code for javascript beginners
    « Reply #3 on: January 08, 2012, 06:27:57 PM »
    How does this help anyone? There's plenty of Javascript tutorials out there that actually explain to you what you're looking at...

    lina19

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: sample code for javascript beginners
      « Reply #4 on: January 09, 2012, 02:19:10 AM »
      Veltas : no you dont really need to have body...they just write it so that both html and the person know the structure...

      i always use <div> tag to structure my pages...

      head can be vital if u want to name your page so that people wanna see the header at first view...


      Linux711 : i did not see any sub-forum for code snippets...if u find one...i would be glad to know....somebody in the chat wanted to know how to get started with javascript and how it is used...i was not able to send him the code...so i posted in in web design so that i can link him the codes...other people can start from this code as well...i mean manipulate it with other textboxes etc...and getting the value in javascript and manipulate it more...like simple addition...subtraction etc....

      Raptor: if somebody asks me...im going to explain...even 100 of times...i wont mind...nobody asks till now...
      just like u said about there are plenty of tutorials...then why are we here if there are plenty of tutorials??i have been in chat for a while...and many people dont like to read tutorials...they like spoon feeding and being guided.....im here if they ask...if somebody wana learn and want to apply the code depending on what he/she needs...i will help him/her definitely...


      Raptor

      • Guest
      Re: sample code for javascript beginners
      « Reply #5 on: January 09, 2012, 06:52:53 AM »
      A lot of people don't like to think about the consequences of global warming either. Not wanting to read guides and tutorials is just another way of saying they're inherently lazy.

      Still, I applaud your willingness to help. Don't get me wrong.

      I do find it a bit odd that you think <div> can replace <body>. What are you basing that on?

      lina19

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: sample code for javascript beginners
        « Reply #6 on: January 09, 2012, 07:47:04 AM »
        <div> can replace <body>...no i didnt say i replace body with div...never....i just mean i dont find the importance of body...they are different things....what i mean is that...people tend to use "body" so that they give a structure to their content....like header then follow by body...then footer...things like that...

        what i wana say...is that...for me i do not see the importance of body....i dont usually use body for all my scripts...if ever it has an importance, i would be glad if somebody points it to be.

        but people tend to think to make a page work...u need to have body...header...just like he/she asked...because a tutorial has told him/her to do so......its my opinion...i accept others' opinion as well....the aim is to help people...so...whatever u people suggest also might be useful...

        Raptor

        • Guest
        Re: sample code for javascript beginners
        « Reply #7 on: January 09, 2012, 07:57:02 AM »
        Javascript is supposed to go into the header according to XHTML standards.

        Where did you read that the <body> has become obsolete?


        lina19

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Unknown
          Re: sample code for javascript beginners
          « Reply #8 on: January 09, 2012, 08:14:05 AM »
          i never said its obsolete....i have just given my opinion....that I DONT SEE ITS IMPORTANCE...if u are seeing its importance...i wouldnt mind u telling it to me...

          i have tested my script many times without body tag...and it works on different browsers.....safari...firefox...ie...go ogle chrome...opera...

          and regarding,
          "A lot of people don't like to think about the consequences of global warming either. Not wanting to read guides and tutorials is just another way of saying they're inherently lazy."
          not necessarily.....not all people are the same..some might be lazy and others might have gone through tutorials, but still are confused....i would say it depends on people determination to do something and also perhaps some people want to feel secured by having guidance...i know a few people who are really productive....their result of their work are better than me....but they need some kind of guidelines to follow or instruction...like what they need to look for...what they should....if u give them 1 single phrase...and told them to go and look information about it...they will come with all sort of unrelevant information and they are totally confused, they wont know in what direction to go or start.....i wont say that they are 100 percent depending on others...they just need like 10 percent of guidance....then the 90 percent they can manage......it really depends on who they are...we cant just say because of laziness....


          for your other questions:
          Javascript is supposed to go into the header according to XHTML standards.

          i dont know...i never read about XHTML standards...
          im giving opinions on my working experience...
          thx for pointing it to me...i will read about it...

          but im aware that we can place javascript in the header tag....i have seen it on many sites when i was new to javascript.... was doing it because i learn it this way...with time i realised it works without the header...just like i posted in the code...it works without being included into header tag......

          Raptor

          • Guest
          Re: sample code for javascript beginners
          « Reply #9 on: January 09, 2012, 08:17:19 AM »
          Oh yeah, it'll work fine outside. It's just that I think the <header> tag is important because that's where the standard says certain stuff goes.

          I'm not sure if leaving out the <body> tag is such a good idea. Maybe it'll work but I've never actually seen anyone suggest it. It's definitely going to render in quirk mode if you do that.

          Veltas



            Intermediate

            Thanked: 7
            • Yes
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Linux variant
          Re: sample code for javascript beginners
          « Reply #10 on: January 09, 2012, 08:19:29 AM »
          i never said its obsolete....i have just given my opinion....that I DONT SEE ITS IMPORTANCE...if u are seeing its importance...i wouldnt mind u telling it to me...

          It's how we define HTML, the only reason the page works without it is because browsers attempt to understand poorly written HTML anyway.

          A lot of people don't like to think about the consequences of global warming either.

          No such thing!

          lina19

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Unknown
            Re: sample code for javascript beginners
            « Reply #11 on: January 09, 2012, 08:36:44 AM »
            http://seo.yu-hu.com/glossary/Body_html.htm
            http://www.rwgusa.com/body_tags.htm

            yea...i read about it cause i never wanted to know its importance....i found it unimportant because for my usage it was working fine....thx due to you i read about it....
            so...these pages mostly said that we use tags because of search engines......my pages were not working with search engines...so they were ok for me...but its good to know now...
            but i truely think...when u want to make somebody learn i really we shouldnt talk about things like search engines etc....when they grasp the languages properly...then we can tell them about other things....like doubts etc...i truely think...we need to show people how to input...process...and output the result...thats the first thing to do...afterall  they want the result....when they start learning about servers etc...then we can tell beginners about all these important details...

            veltas:
            "It's how we define HTML, the only reason the page works without it is because browsers attempt to understand poorly written HTML anyway."
            agree with u...

            Raptor

            • Guest
            Re: sample code for javascript beginners
            « Reply #12 on: January 09, 2012, 08:40:54 AM »
            It's not about search engines, it's about setting up a proper document.
            The first thing someone new to HTML should learn is:

            <html>
            <Head>
            </head>
            <body>
            <body>
            </html>


            lina19

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Unknown
              Re: sample code for javascript beginners
              « Reply #13 on: January 09, 2012, 08:55:03 AM »
              <html>
              <Head>
              </head>
              <body>
              <body>
              </html>


              u follow this format because u want your work to be efficient....resulting in extracting pages correctly by browsers or search engines...like professional people do...how can u expect beginners to work professionally??
              even by telling somebody...u know u have to follow these steps...

              they will keep on asking all sort of unrelevant questions like the same question....."whats the importance of <body>"...whats the importance of <head>...when u will start explaining.."u know there are search engines etc..." would beginners understand search engines??....there will be too much of information to explain...and people who are new to something...want to see how something works...not how it is logically....when they start seeing things...then they can start imagining how the content should be...it really depends with whom you dealing...some people are really new to programming...you cant expect all people to understand this structure at first time....its better u do what they need first...then start adding up on what u showed them...

              its better to give people who are new to something very limited knowledge...once they are used to it...they will feel at ease...and u can add other technical issues...



              i

              Raptor

              • Guest
              Re: sample code for javascript beginners
              « Reply #14 on: January 09, 2012, 09:03:40 AM »
              That's how any book on HTML starts because that's how people agreed to use HTML so that it would give the same visual experience on every browser.

              When they ask you the importance of body you tell 'm that's where the code goes because that's how the browser knows how to render the page. If they're still asking stupid questions, it's safe to assume you're going to have to perform an emergency lobotomy.

              It's kind of like teaching kids that if they want to bike, they need to use the pedals . I don't know how else I can explain it to you.