473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Onclick Display Message

ullevi83
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:

Expand|Select|Wrap|Line Numbers
  1. <form name="form1">
  2.   <input type="text" name="textbox1" onclick(displaymessage)>
  3.   <input type="text" name="textbox2" onclick(displaymessage)>
  4. </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?

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function DisplayMessage()
  3.   {
  4.     var textbox_name = document.getElementById.name;
  5.  
  6.     if(textbox_name=="textbox1")
  7.         {
  8.         alert(textbox_name);
  9.         }
  10.   }
  11. </script>
Can anyone shed any light on a suitable solution to my problem? Thanks for your help in this.
Mar 31 '10 #1

✓ answered by kk1234

Expand|Select|Wrap|Line Numbers
  1.    1. <form name="form1">
  2.    2.   <input type="text" name="textbox1" onclick(displaymessage)>
  3.    3.   <input type="text" name="textbox2" onclick(displaymessage)>
  4.    4. </form>
  5.  
You need to have this:
onclick="displaymessage()"

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

9 11480
Dormilich
8,658 Expert Mod 8TB
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
Mar 31 '10 #2
Sorry for wasting your time.
Mar 31 '10 #3
Dormilich
8,658 Expert Mod 8TB
it’s not wasting my time, but there would be so many things to fix, that it’s easier to start anew.
Mar 31 '10 #4
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.
Mar 31 '10 #5
Dormilich
8,658 Expert Mod 8TB
@ullevi83
understanding is difficult when you realize at first glance, that the code’s syntax ain’t right at all.

@ullevi83
have you used document.getElementById() before? (your syntax is totally wrong)

@ullevi83
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.
Mar 31 '10 #6
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.
Mar 31 '10 #7
kk1234
3
Expand|Select|Wrap|Line Numbers
  1.    1. <form name="form1">
  2.    2.   <input type="text" name="textbox1" onclick(displaymessage)>
  3.    3.   <input type="text" name="textbox2" onclick(displaymessage)>
  4.    4. </form>
  5.  
You need to have this:
onclick="displaymessage()"

I think that should work, and I think that's what your asking if not, sorry!
Apr 2 '10 #8
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!
Apr 6 '10 #9
Frinavale
9,735 Expert Mod 8TB
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
Apr 6 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
2
by: webdeveloper | last post by:
sorry about that, This is the event handling element: <div id="menu"> <ul> <li>.... <li><a href="javascript:expand_menu(document.getElementById('extend'))" id="extend">Text <img src=""...
3
by: Danigan | last post by:
I could about swear this was working perfectly while I was adding some other functionality somewhere else. I now removed that functionality and it doesn't work. If someone could find what I broke,...
2
by: stevemtno | last post by:
I've got a problem with a web page I'm working on. I have 4 modules - one of them has 2 tabs, two of them have 4 tabs. When the user clicks on the tabs, the content below them changes. However, when...
1
by: Jacqui | last post by:
Hi, I am trying to write a webpage that has a form on it, which gets submitted when a button is pressed, but also has an onclick event which does some DOM manipulation to display a waiting page....
1
by: Amit1980 | last post by:
I have to toggle the arrow image on onclick event. Here is the code with the required functionility. What I want now is, when the page loads there will be right arrow images. The arrow should be...
9
by: skultetc | last post by:
Hey all, I have a div displayed as a block with an onclick event that shows/ hides a different div underneath it. There is a link within the first div that takes the user to a different page. My...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
1
rahulephp
by: rahulephp | last post by:
CSS Tabs - contents of a div disappear in IE & onclick is not working Here is the code: Swaps the "active" tab and "inactive" tab and swaps out the new content via the display style attribute: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.