Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now