Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I run javascript function from text like [some text]

Posted on 2008-10-03
4
Medium Priority
?
800 Views
Last Modified: 2013-11-19
I want to run a javascript function from text like [some text].  I can do it from a button and hyper link as shown below. THanks.

<a href="javascript:showGRID()"><font face="Arial" size="2">Click here to show grid.</font></a>
 
 
<INPUT  id=collateral onclick=showGRID(); type=button value="Show Grid" name=showGrid tabindex="99">

Open in new window

0
Comment
Question by:doindata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:JasonChandler
ID: 22638320
Hi there this should do it:
<p onclick="ShowGrid();"> <ul>Your text here</ul> </p>

However you should add a stype to the <p> tag to add a hand cursor to the text.
See my code snippet

<!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" />
<title>Untitled Document</title>
 
<script type="text/javascript">
function ShowGrid(){
 
}
</script>
<style type="text/css">
<!--
.pJava {
	cursor: help;
	text-decoration: underline;
}
-->
</style>
</head>
 
<body>
 
<a href="javascript:showGRID()"><font face="Arial" size="2">Click here to show grid.</font></a>
 
 
<p class="pJava" onclick="showGRID()"> Your text here </p>
</body>
</html>

Open in new window

0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 200 total points
ID: 22638322
One option would be to enclose the text with SPAN tags, e.g.:
<span onclick="alert('Text clicked');">[some text]</span>

Open in new window

0
 
LVL 2

Expert Comment

by:JasonChandler
ID: 22638325
Sorry I made a mistake..igno the <ul> tags in my reply. The Code snippet is ok. This is one way to do it.
0
 

Author Closing Comment

by:doindata
ID: 31502926
Thanks, I ended up using the  tag but I will look at  as well.  
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question