Solved

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

Posted on 2008-10-03
4
796 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 50 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 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