www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help with a simple code

  1. #1
    Join Date
    Feb 2013
    Posts
    9

    Help with a simple code

    Hello guys, I'm new to javascript, and during my learning I came across a little problem:


    Code:
     
    
    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to call a function with arguments</p>
    
    <form>
    <input type="text" id="occu" name="occupation" /><br>
    <input type="button" name="submit" value="Submit" />
    </form>
    
    <br><br>
    <button type="button" onclick="MyFunction(x, 'harry')"> Click here </button>
    
    <script>
    var occupation = new string;
    var name = new string;
    var x=document.getElementById("occu");
    function MyFunction(Occupation, Name)
    {
    window.alert("Welcome to you, " + Name + " the " + Occupation);
    }
    
    </script>
    
    </body>
    </html>
    What's supposed to happen is that the user enters something in the dialog box, (lets say wizard) and then when the other button is clicked, the alert will show "Welcome to you, harry the wizard". I can't find why it won't work.

    Also, if I directly add this line:
    var x="wizard" it still won't work.


    Thanks in advance

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,133
    onclick="MyFunction(document.getElementById('occu').value, 'harry')
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Feb 2013
    Posts
    9
    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles