Onclick Display Message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ullevi83
    New Member
    • Mar 2010
    • 5

    Onclick Display Message

    Guys,

    First post on Byte, so hello all!

    I was wondering if I could pick somones brain regarding what I hoped would be an easy message display function, unfortunately it is causing me a lot of frustration.

    I am looking to display an alert box with a custom message depending on what textfield a user clicks on.

    For example, if I had a simple form with the following:

    Code:
    <form name="form1">
      <input type="text" name="textbox1" onclick(displaymessage)>
      <input type="text" name="textbox2" onclick(displaymessage)>
    </form>
    I was hoping the function would be as simple as something like this (but I have little experience using getElementById) and not sure you can even do this?

    Code:
    <script language="javascript">
    function DisplayMessage()
      {
        var textbox_name = document.getElementById.name;
    
        if(textbox_name=="textbox1")
            {
            alert(textbox_name);
            }
      }
    </script>
    Can anyone shed any light on a suitable solution to my problem? Thanks for your help in this.
    Last edited by Dormilich; Mar 31 '10, 11:17 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if you not have read a JavaScript tutorial until now, do it (see this forum’s offsite links).

    discard anything of what you have posted here

    Comment

    • ullevi83
      New Member
      • Mar 2010
      • 5

      #3
      Sorry for wasting your time.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        it’s not wasting my time, but there would be so many things to fix, that it’s easier to start anew.

        Comment

        • ullevi83
          New Member
          • Mar 2010
          • 5

          #5
          I understand what your saying Dormilich but I gave that as an example of what I was trying to achieve, I made it easy for people to understand what I was talking about.

          The long and short of it is, I can read the value of any form element and manipulate it to suit, but I have searched several javascript sites to find a solution to my problem and I have come to the conclusion it can't be done.

          I may well be wrong but obviously functions that display an alert when a specific named textbox is clicked does not get used very often.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by ullevi83
            I understand what your saying Dormilich but I gave that as an example of what I was trying to achieve, I made it easy for people to understand what I was talking about.
            understanding is difficult when you realize at first glance, that the code’s syntax ain’t right at all.

            Originally posted by ullevi83
            The long and short of it is, I can read the value of any form element and manipulate it to suit, but I have searched several javascript sites to find a solution to my problem and I have come to the conclusion it can't be done.
            have you used document.getEle mentById() before? (your syntax is totally wrong)

            Originally posted by ullevi83
            I may well be wrong but obviously functions that display an alert when a specific named textbox is clicked does not get used very often.
            I think that is because of its intention. why would anyone *want* an alert, when clicking in a text box?
            most people click into a textbox to write something in, not to get something shown.

            Comment

            • ullevi83
              New Member
              • Mar 2010
              • 5

              #7
              Your right in what your saying why would anyone want an alert when clicking in a text box, well my boss wants me to do this when they click on a particular product, its not beyond the realms of possibility that before someone enters a value into a form that you may want them to know something about that product?

              I found the answer to my solution, but thanks for the little help you offered.

              Comment

              • kk1234
                New Member
                • Mar 2010
                • 3

                #8
                Code:
                   1. <form name="form1">
                   2.   <input type="text" name="textbox1" onclick(displaymessage)>
                   3.   <input type="text" name="textbox2" onclick(displaymessage)>
                   4. </form>
                You need to have this:
                onclick="displa ymessage()"

                I think that should work, and I think that's what your asking if not, sorry!

                Comment

                • ullevi83
                  New Member
                  • Mar 2010
                  • 5

                  #9
                  Thanks KK1234 I figured it out for myself but came to the same conclusion.

                  Have you considered becoming moderator for this forum? Your much more help than the current moderator!

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    We all have to start somewhere when learning something new but this forum expects you do your part in learning the basics of whatever technology you're working with. After you have done research into the topic, and if at this point you have a question about something you don't understand, that's when you should post your question.

                    When someone post a bunch of stuff that is so obviously wrong to anyone who has even a very basic understanding of any technology (in this case JavaScript) it's frustrating. I mean, why wouldn't it be frustrating? The person who's doing the answering has to put more effort into explaining what's wrong than they should have to....to someone who hasn't put any effort into trying to figure out what's wrong for themselves. This insult isn't apparent to first time posters or people who are very new to a technology. You don't usually make this realization until you have answered hundreds (or thousands) of questions.

                    Anyways, enough about forum ethics and on to helping you find tutorials so that you can learn the basics so that we can help you out!

                    In the JavaScript forum there is a "sticky" post at the very top of the form that contains links that are helpful in learning the basics of JavaScript to get you started (it's "stickied" to the top so that you can always see this post when you first come to the JavaScript answers forum).

                    Since I don't think you saw this sticky post, here is a link to it: Offsite Links. Here on bytes there are also a number of articles written by experts, members, and moderators that can further help you with a topic. You can view these articles in the JavaScript Insights section.


                    Cheers!

                    -Frinny

                    Comment

                    Working...