Solved

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

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

631 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