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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calling a variable


    Since there are alot of people who know their stuff here, got a javascript question.

    I'm a complete newb to javascript and have an assignment for class(Intro to web design) I can't fiqure out for the life of me.

    I need to create 2 text boxes and 2 buttoms that perform certain tasks in javascript.

    The alert button I fiqured out(Display input from textbox1 in an alert window).

    The switch button, I'm stuck on. I need to take the input from textbox1 and place in textbox2 when clicked. I declared the variable "switch" to use for that function. Here is the code I have so far. The question marks are where I'm stuck. I don't need this done for me, but help is appreciated.

    Thanks in advance on this one.

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>

    <title>Brad Hanna's lab4/19</title>

    <script type="text/javascript" language="javascript">

    var switch;
    switch = (stuff1);
    function helloalert(input)
    {
    window.alert(input)
    }
    </script>

    </head>

    <body>

    <h1>Lab 4/19</h1>

    <p>Type anything in the first field</p>

    <form>
    <input name="stuff1" type="text" />
    <input name="stuff2" type="text" /><br/>
    <input name="alert" type="button" value="Alert"
    onclick="helloalert(form.stuff1.value)" />
    <input name="switch" type="button" value"Switch"
    onclick=?????? />
    </form>



    </body>

    </html>
    Last edited by hanna975; 04-24-2004 at 03:17 AM. Reason: It seemed like I was asking for it done for me

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,239
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    'switch' is a reserved word or keyword in JavaScript, that is part of the language syntax which is not available as an identifier name for a variable or function.

    Also,it is not a very good idea to give elements or variables the same NAMEs as their VALUEs, as it can cause confusion. e.g. Name = "Alert" Value = "Alert", or var message = "message"
    Last edited by Philip M; 04-24-2004 at 11:36 AM.

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks,
    Can you tell I'm new at this. We're two days into javascript and I'm already getting stuck. Glad the semester is almost over. I can work on this more on my free time.

  • #4
    Regular Coder
    Join Date
    Jan 2004
    Location
    Maryland
    Posts
    468
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When you switch two things you will need to save one in a variable.
    Code:
    <html>
    <head>
    <script>
    function sSwitch(txt1,txt2){
    var saveMe = txt1.value
    txt1.value=txt2.value
    txt2.value=saveMe
    }
    
    </script>
    </head>
    <body>
    
    <input type = "text" id="i1" /><br />
    <input type= "text" id="i2" /><br />
    <input type="button" onclick="sSwitch(document.getElementById('i1'),document.getElementById('i2'))" />
    </body>
    
    
    </html>

  • #5
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks squirellplaying,

    I was having problems calling my variables
    I'll have to get my c++ mentality back
    I love these forums, everyone is willing to help those in
    need. Here's a good one if your into pocketpc's. They've
    helped me with things like creating themes to setting
    up and securing my wireless network.
    They're mostly into the Dell Axim's but all are welcome.

    WWW.AXIMSITE.COM

  • #6
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have Javascript at school in the US?!

    ...***Dreaming***
    <JPM />

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Location
    Maryland
    Posts
    468
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Me too. I have (x)html/css, javascript, java, asp, mysql, and C++(It's one of the C, not sure which one.). That's just in highschool .

  • #8
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm in college and an adult student at that. When I was in highschool, we were lucky to have computers at all. I'm not even sure what operating system they used.(I didn't do well with computers back then). The monitors were even those black and green screens. Monochrome, I think. This was back in the late 80's where the internet was just a year or two old. I'm so glad that technology has made the advances it has made. It's kind of hard to believe we've come this far.


  •  

    Posting Permissions

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