473,748 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Onclick Display Message

ullevi83
5 New Member
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
9 11508
Dormilich
8,658 Recognized Expert Moderator Expert
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
ullevi83
5 New Member
Sorry for wasting your time.
Mar 31 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
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
ullevi83
5 New Member
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 Recognized Expert Moderator Expert
@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.getEle mentById() 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
ullevi83
5 New Member
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 New Member
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="displa ymessage()"

I think that should work, and I think that's what your asking if not, sorry!
Apr 2 '10 #8
ullevi83
5 New Member
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 Recognized Expert Moderator Expert
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
9174
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 in the status bar 'Symantec Corporation' whenever anyone mouses over (onMouseOver) my image or link OR when one clicks while holding the left mouse down (onClick) on the same image or link. Upon releasing the mouse (onMouseOut), the
5
2586
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 is the code for this. the onclick event calls a javascript function which I put an alert in the firt line to tell me if its working. It does work in IE. Any ideas on how to get netcrap... oops, I'm sorry, netscape to fire the onclick event? ...
2
1969
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="" id="arrow" src="arro-u.gif"</a>
3
8401
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, please tell me. I am new to using JavaScript seriously (probably been tweaking individual lines of code for 5 years) and after staring at my mistake for hours I probably can no longer see it. Intended functionality: 3 links that can be clicked to...
2
1960
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 the user clicks on the tab (any tab), the browser goes back to the top of the page (I'm assuming it's refreshing, I'm not sure). I'm attaching the JS code below, along with the 2-tab version of the module and its accompanying CSS. Any help will be...
1
3199
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. The issue that I am facing is that in Safari, a blank screen is being displayed rather than the waiting page. This is only happening if there are form tags around the button
1
5920
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 chenge to down arrow when I the row expands to dispaly the child links. and if the collaps to hide child link the arrow should change back to right arroe image. In the below e.g code you will not be able to see the arrow images. Here is the code I have....
9
10027
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 problem is that if the user clicks the link, the onclick is also executed and the div underneath is shown/hidden before the browser changes pages, which makes things a little clunky looking. Is there any way to keep the div's onclick from firing...
5
8688
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
4309
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: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
0
8995
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.