/    Sign up×
Community /Pin to ProfileBookmark

javascript function on A tag in HTML

Hi Friends,
I create a A link with a javascript function. i want to send a string test to a pop window.

<a href=”javascript:go(info(“test”))”>summary</a>
I got a error message as “test undefined” I can not call a function.
What is wrong?
Thanks for any help!

Fairfax

————JavaScript codes
<Script language=”JavaScript” type=”text/javascript>
{
function info(p) {
alert(p);
msg=window.open(“”,”msg”,”height=340,width=250,left=10,top=40″);
msg.document.write(“<html><title>Windows!</title>”);
msg.document.write(“<body onblur=window.close()>”);
msg.document.write(“Search Instructions:”);
msg.document.write(“<br>1.” + p +”);
msg.document.write(“</body></html><p>”);

}
</Script>

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@tabzterNov 07.2005 — change <a href="javascript:go(info("test"))"> to <a href="javascript:info([B]'test'[/B])">
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 08.2005 — Hi tabzter,

Thanks for your help.

I changed to <a href="javascript:info(''test'')">. But I got an error message

"object expect" any wrong in my code?

Thanks

Fairfax
Copy linkTweet thisAlerts:
@konithomimoNov 08.2005 — Add in a semicolon to end the line, and look at the quotation marks around test. You have two apostrophes instead of one quotation mark. Use either of these:

<a href="javascript:info('test');">

<a href="" onClick="javascript:info('test');">
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 08.2005 — or <a href="javascript:info('test')">click here</a>

message as objected expected
Copy linkTweet thisAlerts:
@konithomimoNov 08.2005 — I would just do:

<a href="" onClick="info('test')">Click Here</a>
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 08.2005 — Hi konithomimo,

I changed to test<b> <a href="" onClick="javascript:info('test');">click here</a></b>

But It go to window explorer. no any error message.

It seems code does nor fire javaScript function info().

Thanks for you help. which is wrong?

Fairfax
Copy linkTweet thisAlerts:
@konithomimoNov 08.2005 — <i>
</i>&lt;a href="" onClick="info('test')"&gt;Click Here&lt;/a&gt;


and

<i>
</i>&lt;script type="text/javascript"&gt;
{
function info(p)
{
alert(p);
window.open("","msg","height=340,width=250,left=10,top=40");
msg.document.write("&lt;html&gt;&lt;title&gt;Windows!&lt;/title&gt;");
msg.document.write("&lt;body onblur=window.close()&gt;");
msg.document.write("Search Instructions:");
msg.document.write("&lt;br&gt;1." + p +);
msg.document.write("&lt;/body&gt;&lt;/html&gt;&lt;p&gt;");

}
&lt;/script&gt;


You were missing one quotation mark and had an extra one. I would have to see what is happening to figure out anyother problems. And you named your window twice, as the red parts show:

<i>
</i>[COLOR=Red]msg[/COLOR]=window.open("",[COLOR=Red]"msg"[/COLOR],"height=340,width=250,left=10,top=40");
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 08.2005 — Hi Hi konithomimo,

That codes works well in click button at input box.

I want to move to inline at a tag. but it not works. it seem it does not call javascript function.

msg can be make more line based on information to be displayed.

test<b> <a href="" onClick="javascript:info('test')">Benchmark</a></b>

Thanks for your time.

Nice day

Fairfax
Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — test<b> <a href="#" onClick="info('test')">Benchmark</a></b>
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 09.2005 — Hi Konithomimo,

Thanks for your help.

However. It does not work. and message as object expected.

also i found that path checged to file:///C:/test.html#

that means codes addeds a # to path in URL?

I alse try to this code <a href="javascript:void(0)" onClick="info('test')">Benchmark</a>. It works in pict item. but it does not works in thsi code. strange for this issue? any solution?

Thanks for friends' time.

Fairfax
Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — Fix this line:

msg.document.write("<br>1." + p +);

it should be:

msg.document.write("<br>1." + p);

and then post all of your code so that I can see exactly what is happening.
Copy linkTweet thisAlerts:
@konithomimoNov 09.2005 — Here is your code atlered and working:
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function info(p)
{
alert(p);
var msg = window.open("","newwin","height=340,width=250,left=10,top=40");
var tmp = msg.document;
tmp.write('&lt;html&gt;&lt;title&gt;Windows!&lt;/title&gt;');
tmp.write('&lt;body onblur=window.close()&gt;');
tmp.write('Search Instructions:');
tmp.write('&lt;br&gt;1.' + p);
tmp.write('&lt;/body&gt;&lt;/html&gt;');
tmp.close();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;&lt;a href="" onClick="info('test')"&gt;Benchmark&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 10.2005 — Hi konithomimo,

Thanks so much.

it works well.

Nice day

Fairfax
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 11.2005 — Hi Kion and Friends,

Thanks for you help.

I changed your code. However, It will close parent window after clicking .

what issue?

--------code

<html>

<head>

<script type="text/javascript">

function info(p)

{

alert(p);

var msg = window.open("","newwin","height=340,width=250,left=10,top=40");

var tmp = msg.document;

tmp.write('<html><title>Windows!</title>');

//tmp.write('<body onblur=window.close()>');

tmp.write('Search Instructions:');

tmp.write('<br>1.' + p);

tmp.write('</body></html>');

tmp.close();

}

</script>

</head>

<body><a href="" onClick="info('test')">Benchmark</a>

</body>

</html>
Copy linkTweet thisAlerts:
@jimmyzhuauthorNov 14.2005 — Hi Kion and Friends,

Thanks for you help.

I changed your code. However, It will close parent window after clicking .

what issue?

--------code

<html>

<head>

<script type="text/javascript">

function info(p)

{

alert(p);

var msg = window.open("","newwin","height=340,width=250,left=10,top=40");

var tmp = msg.document;

tmp.write('<html><title>Windows!</title>');

tmp.write('<body >');

tmp.write('Search Instructions:');

tmp.write('<br>1.' + p);

tmp.write('</body></html>');

//tmp.close();

}

</script>

</head>

<body><a href="" onClick="info('test')">Benchmark</a>

</body>

</html>
×

Success!

Help @jimmyzhu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...