Menu
What is the best way to do this sort of thing.
onClick=”javascript: function(‘value’);”
onClick=”function(‘value’);”
onClick=”return function(‘value’);”
onClick=”javascript: function(‘value’)”
onClick=”function(‘value’)”
onClick=”return function(‘value’)”
Is there a way you are “suppose” to do it?
onClick="javascript: function('value');"[/quote]
<i>
</i><meta http-equiv="Content-Script-Type" content="text/javascript">
I believe that putting javascript inline has been depreciated by W3C.[/quote]
The use of the javascript: psuedo-protocol identifier is probably unnecessary in most cases -- just keep in mind that it is valid for those times when you may need to use it. The semicolon is also probably unnecessary in most cases but, again, I would recommend that you make a habit of always using it -- as it is good programming practice to do so.[/quote]
... if you're coding for the IE browser, that is. The IE browser (and all versions of the NS browser, for the matter) always support the following:[/quote]
It is documented at MSDN.[/quote]I've searched the MSDN site and could find neither example nor description of your your special little construction. The only thing close is the JavaScript protocol (
I said I've used it in all IE and NS browsers and versions (on a Windows platform). That's all... ...and that's all most of the people will care about[/quote]Perhaps, but you need to make it clear to them that your special little construction is not only unnecessary but it might cause harm on those other browsers. Which is what was meant when I wrote that it was always wrong. But you took offence at that. And I suspect that there are more people out there than you think who do care that their pages work on all browsers. I'm quite sure that you don't vare very much for those using Braille and audio browsers but other do - and some of them out of a well founded fear of legal action.[/font]
[i]Originally posted by Nigorr [/i]
[B]What is the best way to do this sort of thing.
onClick="javascript: function('value');"
onClick="function('value');"
onClick="return function('value');"
onClick="javascript: function('value')"
onClick="function('value')"
onClick="return function('value')"
Is there a way you are "suppose" to do it? [/B][/QUOTE]
[i]Originally posted by Dave Clark [/i]
It was your use of the word "always" that I took offense to -- since it obviously was [b]required[/b] in my situation. [/QUOTE]
[i]Originally posted by Dave Clark [/i]
[B][list]
[*]You didn't read all the details. My situation required using [b][i]two[/i][/b] scripting languages in the [b][i]same[/i][/b] document. Nobody addressed this issue -- they weren't going to touch what they knew nothing about. Instead, they were satisfied to baselessly criticize.
[/QUOTE]
[*]Nobody proved what I am doing is not valid. The fact that it fixed an error in the browser proves that it [b][i]is[/i][/b] a valid method -- some people just can't accept that.
[/QUOTE]
[i]Originally posted by Dave Clark [/i]
[B]You're still not reading/listening to all the details. I'm not talking about SCRIPT blocks. I'm talking about [b][i]inline[/i][/b] script coding.
[/QUOTE]
[i]Originally posted by Dave Clark [/i]
I didn't say inline [b][i]function calling[/i][/b], I said inline [b][i]script coding[/i][/b]. [/QUOTE]
[CODE]
<form>
<input type"button" value="Click here" onclick="Popup()">
</form>
[/CODE]
You can use a form button:
[CODE]
[/QUOTE]
<form>
<input type"button" value="Click here" onclick="Popup()">
</form>
[/CODE]
that would be great, but what if someone else owns the button and I don't have control over it?
http://www.pandorabots.com/pandora/talk?botid=875d96ffae366536 [/QUOTE]
<i>
</i>onload = function(){
[I]myobject[/I].onclick=function(){somefunction()}
}
Regarding to the main topic. Why, on Earth, to use a construction on line like
<tag onclick="javascript:somefunction()" />
(no matter that it is obsolate) when you can write it short as
<tag onclick="somefunction()" />[/QUOTE]
I currently ran across an issue in Chrome where[COLOR="Red"]I HAD[/COLOR] to use the convention of putting "javascript:" before the function of my onclick event. [/QUOTE]
No way. There are no circumstances which should oblige a coder to use the [B]javascript:[/B] old fashioned token. On the contrary, most of the time that syntax will bring errors. So, I seriously doubt that [I]YOU HAD[/I] to do that by all means. can you give me an example? ?[/QUOTE]Agreed. That "javascript:" just is a label pointing to a statement, it has nothing to do with being it being executed as JavaScript. I, also, would love to see a sample.
<i>
</i><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function skipOffer2(){
alert('It works!')
}
</script>
</head>
<body>
<?php
$design='foo';
$design_code = '<div class="skip" onclick="skipOffer2();">'.$design.'</div>';
echo $design_code; ?>
</body>
</html>
So you're saying that a bad Apache or PHP installation is actually causing my web server to traverse my code and actively remove my inline javascript events?[/QUOTE]
[CODE]<input type="hidden" name="test" id="test" value="onclick%3D%22alertMe%28%29%22" />[/CODE]
[CODE]<div class="skip" onclick="alertMe()">[/CODE]
[CODE]<div class="skip" onclick="">[/CODE]
1. On my initial page I have a form with a hidden field like this:
[CODE]<input type="hidden" name="test" id="test" value="onclick%3D%22alertMe%28%29%22" />[/CODE]
[/QUOTE]
<i>
</i><form action="x.php" method="get" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="test" id="test" value="onclick,alertMe">
<input type="submit" value="Submit">
</form>
<i>
</i><script type="text/javascript">
function alertMe(){
alert('I am here!');
}
</script>
...
<?php
$data=explode(',',$_GET['test']);
$handler=$data[0].'='.$data[1].'()';
echo '
<div '.$handler.'>click</div>
';
?>
[CODE]<html>
<head>
</head>
<body>
<form name="testForm" method="get" action="test2.html" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="test" id="test" value="onclick%3D%22alertMe%28%29%22" />
<input type="submit" value="Skip" />
</form>
</body>
</html>[/CODE]
[CODE]<html>
<head>
<style type="text/css">
.skip {cursor: pointer; cursor: hand; color: blue;}
</style>
</head>
<body>
<div class="skip" onclick="alertMe()">
Clicking this will do nothing in Chrome!
</div>
<script type="text/javascript">
function alertMe() {
alert('hello, world!');
}
</script>
</body>
</html>[/CODE]
If this is indeed a bug in Chrome, should I file a bug report with them?[/QUOTE]
Good to know. I've tried removing the encoding on the data and it's still happening.
I'll try to dig up that bug report, but I believe that this issue is slightly different.
The fact that Chrome is not encoding double quotes properly isn't the issue. Since I'm not using the (improperly) encoded data, it should have no effect on the page functionality. If I were to use this encoded data on the page, then yes, I would expect some errors to appear as you've illustrated in your code samples. [B]But since I'm not[/B], it leads me to believe there are other underlying issues.[/QUOTE]
... that I needed to make it <a href="javascript:myFunction('parameter')">DisplayText</a> or it took me to the classic "WEB PAGE COULD NOT BE FOUND AT ... " However, when I created a button such as: <input type=button onClick="myFunction('parameter')" value="DisplayText"> the "javascript:" was not needed in order for the input to function. I am still boggled on why this is, but I hope this information helps someone.[/QUOTE]
[CODE]myFunction('parameter');return false;[/CODE]
I don't believe it's [I]required[/I]. Maybe Noob used that word a little sparingly. We're just saying that there are certain situations (be it a bug in a browser, or even an unseen error in your own code!) when using [I]javascript:[/I] just works, when other methods don't.[/QUOTE]The problem is that you are using a language construct without knowing what it does. javascript is not a keyword in Javascript, it's being used as a
<a href="#" onclick="any_old_label: alert('Works!');">Works!</a>
Whether that still happens to avoid your bug with the double quotes, I don't know, but that's irrelevant, irrational solutions could make a bug work, but mistakenly using a token used to indicate something in the browser in one specific context everywhere, that is only accidentally valid syntax is always wrong.Whether that still happens to avoid your bug with the double quotes, I don't know, but that's irrelevant, irrational solutions could make a bug work, but mistakenly using a token used to indicate something in the browser in one specific context everywhere, that is only accidentally valid syntax is always wrong.[/QUOTE]
0.1.9 — BETA 5.5