Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Form functions

  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Form functions

    I'm new to Javascript and I'm having a terrible time understanding the whole process. I've had two classes and one assignment that I've spent hours trying to understand and complete and I'm still scratching my head. If anyone can help, I would appreciate it so much. The assignment reads:

    When User Type1 is selected alert the text "a-" in the Username field, "b-" for type 2 and "c-" for Type 3

    Change the alert to a custom function that will put the values "a-" or "b-", "c-" into the Username field.

    Change the focus to the Username field after a user type has been selected.

    This must be a very simple assignment and since I can't begin to understand how to do it...should I just give up the whole idea of learning it?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First of all NEVER EVER GIVE UP!

    I taught myself everything i know, it took alot of hard work and alot of scratching my head. Never give up perservier on through and you'll feel alot better on the other side.

    Heres what i came up with, but Look at it study it see what i did and learn from it, it helps to see real examples.

    --------

    <script language="javascript">

    function changeUser(){

    alert(document.forms[0].Type.options[document.forms[0].Type.selectedIndex].value)
    document.forms[0].userType.value=document.forms[0].Type.options[document.forms[0].Type.selectedIndex].value
    document.forms[0].userType.focus()
    }

    </script>

    <form>
    <select name="Type" onChange="changeUser()">
    <option value="">Select A Type
    <option value="a-">A Type
    <option value="b-">B Type
    <option value="c-">C Type
    </select>
    <BR>
    <input type="text" name="userType">

    -----------

    Hope this helps

    P.S Remeber never give up!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thank you so much for the help. To be honest it is still all so foreign to me but hopefully one day it'll all come together.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm new to Javascript and I'm having a terrible time understanding the whole process.
    Here's my view of the big picture:

    Hypertext Markup Langualge is what makes stuff show up on an internet browser. The boldface in the last sentence was done by using the bolface HTML tag. To keep it simple, let's just say HTML can't do much else other that how things look on the screen.

    In order to give an internet page (an HTML page) some functionality - to allow a page to interact with a user- Javascript was created. The javascript computer language is integrated into HTML. Javascript was designed from the get-go to work with HTML, to compliment it, to allow a web page to do things HTML alone cannot. To use a javascript program we put it as part of the HTML tag we want it to work with.

    Writing an entire Javascript program within an HTML tag would look like quite a mess. To make the javascript program easier to read, understand, write, and modify, we create javascript functions. A function is a chunk of javascript that you write that does something. Any given function usually has a single purpose in mind. An analogy would be the snooze button on your alarm clock. press the snooze button and the alarm is silenced for a pre-determined amount of time. Likewise when we call (press the button so to speak) a javascript function it does what it was programmed to do.

    So,we write functions and from within HTML tags we call them.

    Beyond the mechanics of doing the Javascript / HTML thing, and beyond the syntax of Javascript is learning how to program. Thats' something you can learn only by doing. A good instructor is invaluable here. In most classes the students are all so busy learning the basics of the language and just getting something to work that we tend to pick up that "how to program" very slowly. So hang in there. Grab hold of your teacher whenever you can and ask all the how, what, and why questions you can. Don't give up.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You will one day figure it all out, and your very welcome, And just like RadarBob said Don't Give up
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog


  •  

    Posting Permissions

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