搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

linux I keep getting a error message when running java from scratchpad.

  • 3 回覆
  • 2 有這個問題
  • 7 次檢視
  • 最近回覆由 cor-el

more options
I am trying to run a simple java script from Scratchpad.

<html>
<body>

<h1>My First Web Page</h1>

<script>
document.write("<p>My First JavaScript</p>");
</script>

</body>
</html>
######

<html>
<body>

<script>
function myFunction()
{
var x="",i;
for (i=0;i<5;i++)
  {
  x=x + "The number is " + i + "<br>";
  }
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

the traceback error refers to the var variable;
var x="",i;

I highlight <script> to <script>
and get this error message

/*
Exception: syntax error
Scratchpad:4
*/

this refers to this line var x="",i;

I am trying to run a simple loop that will show the numbers in the loop but the loop crashes.

I need to know how to fix the problem.

jol

<pre><nowiki>I am trying to run a simple java script from Scratchpad. <html> <body> <h1>My First Web Page</h1> <script> document.write("<p>My First JavaScript</p>"); </script> </body> </html> ###### <html> <body> <script> function myFunction() { var x="",i; for (i=0;i<5;i++) { x=x + "The number is " + i + "<br>"; } document.getElementById("demo").innerHTML=x; } </script> </body> </html> the traceback error refers to the var variable; var x="",i; I highlight <script> to <script> and get this error message /* Exception: syntax error Scratchpad:4 */</nowiki></pre> this refers to this line var x="",i; I am trying to run a simple loop that will show the numbers in the loop but the loop crashes. I need to know how to fix the problem. jol

由 cor-el 於 修改

被選擇的解決方法

That is not pure JavaScript code, but HTML code.
You can't run such code via the Scratchpad.
In the second example you are missing a container with the id="demo" and you also are calling the function.

data:text/html;charset=utf-8;base64,PGh0bWw+Cjxib2R5PgoKPGgxPk15IEZpcnN0IFdlYiBQYWdlPC9oMT4KCjxzY3JpcHQ+CmRvY3VtZW50LndyaXRlKCI8cD5NeSBGaXJzdCBKYXZhU2NyaXB0PC9wPiIpOwo8L3NjcmlwdD4KCjwvYm9keT4KPC9odG1sPgo=
data:text/html;charset=utf-8;base64,PGh0bWw+Cjxib2R5Pgo8cCBpZD0iZGVtbyI+PC9wPgoKPHNjcmlwdD4KZnVuY3Rpb24gbXlGdW5jdGlvbigpCnsKdmFyIHg9IiIsaTsKZm9yIChpPTA7aTw1O2krKykKICB7CiAgeD14ICsgIlRoZSBudW1iZXIgaXMgIiArIGkgKyAiPGJyPiI7CiAgfQpkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZGVtbyIpLmlubmVySFRNTD14Owp9Cm15RnVuY3Rpb24oKTsKPC9zY3JpcHQ+Cgo8L2JvZHk+CjwvaHRtbD4K
從原來的回覆中察看解決方案 👍 0

所有回覆 (3)

more options

選擇的解決方法

That is not pure JavaScript code, but HTML code.
You can't run such code via the Scratchpad.
In the second example you are missing a container with the id="demo" and you also are calling the function.

data:text/html;charset=utf-8;base64,PGh0bWw+Cjxib2R5PgoKPGgxPk15IEZpcnN0IFdlYiBQYWdlPC9oMT4KCjxzY3JpcHQ+CmRvY3VtZW50LndyaXRlKCI8cD5NeSBGaXJzdCBKYXZhU2NyaXB0PC9wPiIpOwo8L3NjcmlwdD4KCjwvYm9keT4KPC9odG1sPgo=
data:text/html;charset=utf-8;base64,PGh0bWw+Cjxib2R5Pgo8cCBpZD0iZGVtbyI+PC9wPgoKPHNjcmlwdD4KZnVuY3Rpb24gbXlGdW5jdGlvbigpCnsKdmFyIHg9IiIsaTsKZm9yIChpPTA7aTw1O2krKykKICB7CiAgeD14ICsgIlRoZSBudW1iZXIgaXMgIiArIGkgKyAiPGJyPiI7CiAgfQpkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZGVtbyIpLmlubmVySFRNTD14Owp9Cm15RnVuY3Rpb24oKTsKPC9zY3JpcHQ+Cgo8L2JvZHk+CjwvaHRtbD4K
more options

Sorry for the previously submitted unprecise question. I was told that the code was java.

I'm a python programmer and know zero about java. However I could solve my problem if there were a way to run a python module from scratchpad. Or, maybe a linux script file

If not , my problem is that I am trying to send to a web page entry field a 10 digit number every time I update the web page. So, I need to create a file that will send this number when it is called from Scratchpad. I can create a new file with a new number prior to updating the web page.

I am planning to use a Firefox macro to call Scratchpad to run the file that will submit the new number.

I can deal with the macro but I haven't been successful in sending the number to the entry field and I believe a simple java file will work.

I would appreciate any suggestions.

jimonlinux

more options

You can use code like this to set the value of an input field.

document.getElementById("<id_of_input_field>").value="<value>"

You can also do this via a JavaScript bookmarklet placed on the Bookmarks Toolbar and click that icon.

javascript:void(document.getElementById("<id_of_input_field>").value="##########");

A good place to ask advice about web development is at the MozillaZine "Web Development/Standards Evangelism" forum.

The helpers at that forum are more knowledgeable about web development issues.
You need to register at the MozillaZine forum site in order to post at that forum.