?
Solved

Can I use the onClick event for plain text?

Posted on 2004-04-21
7
Medium Priority
?
363 Views
Last Modified: 2012-06-27
Hi,

trying to call a function through the onClick event of text.
Another question is, can I declare the variable numsquare this way (inside the alert mehtod)?

I want to link text to the function. Something like;

<onclick=squareit(), "Square any number">

Am I at least close? :-(

Here's the function I wrote:

<script language="JavaScript" type=text/javascript>
<!--//
function squareit()
{
alert(var numsquare = prompt("Please enter in any number to be squared.") + "Thank you, " + numsquare + " squared is " + numsquare * numsquare ".")
}
//-->
</script>


TIA,
Tony
0
Comment
Question by:Tony_A
[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
  • 4
  • 2
7 Comments
 
LVL 16

Accepted Solution

by:
jaysolomon earned 300 total points
ID: 10880767
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function squareit()
{
var numsquare = prompt("Please enter in any number to be squared.",0)
alert("Thank you, " + numsquare + " squared is " + numsquare * numsquare +".")
}
// -->
</script>
</head>
<body>
<span onclick="squareit();">"Square any number"</span>
</body>
</html>
0
 

Author Comment

by:Tony_A
ID: 10880822
Works great! But you already knew that! :-P

So would the variable declaration not have worked?
Was it just plain old "bad form" to try to put all that in the alert() method?

Thanks again,
Tony
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10880859
you cannot have var ... = prompt(.......... in a alert.

You should declare all variables either local or global and then in the alert you can show them as i did above.

Glad to have helped and thanks
jAy
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:jaysolomon
ID: 10880860
But why a B?
0
 

Author Comment

by:Tony_A
ID: 10880915
thought you might ask...

I guess cause while you gave me code that worked, I have just as much desire to understand
why I am wrong. I try to use my reference materials for these answers, but they aren't clear about why things are done the way they are.

Such as "cannot have var ... = prompt(.......... in a alert."

Those answers are really important to me too.
Thanks again for help!
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10887929
Thanks

jAy
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 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