Writing Prime Numbers To Table
Jan 26, 2011
I can't seem to get past my function writing
<table rows='10 cols='10' border='1'><tr><th>Prime Numbers(1-100)</th></tr>
<!DOCTYPE HTML PUBLIC "-W3CDTD HTML 4.01EN" "[URL]">
<html>
<head>
<script type="text/javascript">
function primeNumbers() {
var tableCell = 0;
document.write("<table cols='10' border='1'>");
document.write("<tr>"); .....
View 4 Replies
ADVERTISEMENT
Jan 27, 2009
I am taking a javascript class and I need a script that displays the first 1000 prime numbers in a table with 10 numbers per row. I've been trying on my own for about 4 hours now and am really confused. I just started the class and have only started learning javascript 3 days ago.
View 6 Replies
View Related
Jun 23, 2011
So I wrote this piece of code, which should display the first 10,001 prime numbers.
Code:
<html><head>
<title>Problem 7 project euler</title>
</head><body><script>
var x = 3;
var primes = new Array();
primes[1] = 2;
var n = 1;
document.write("PRIME#1= 2" + "<br />")
while (n < 10001){
if (x%primes[n] == 0){
x = x + 2;
}else if ((n + 1) < (primes.length)){
n = n + 1
}else{
primes[(n+1)] = x;
document.write("PRIME#" + (n + 1) + "= " + primes[(n+1)] + "<br />");
x = x + 2;
n = 1
}}
</script>
</body>
</html>
Now the problem is that somehow this code also interprets some non-primes as primes.
View 7 Replies
View Related
Aug 21, 2011
How would you make a alert box that contains a table instead of writing?
View 1 Replies
View Related
Nov 4, 2011
I thought this would be fairly easy, but I've searched and searched and came up with nothing that works. I just need to add row numbers to my table. I already have the first column blank, I just need the row numbers stuck in there. I've found examples using .index() and .rowindex, but I can't find anything that works right.
View 5 Replies
View Related
Apr 8, 2006
I'm not too experienced in programming, all I know is from practicing so don't be surprised if I made some mistakes. One mistake that I know is that the page is absolutely non-standard, but I don't really care about things like web-standards when making these little scripts.
As I'm Hungarian and not English, this code (functions, vars) was also written in Hungarian, but I translated it to be a bit more readable for Englishpeople. If it's still not clear, I can comment it.
<style>
body{text-align:center; font-family:arial;}
.answerbox,.detailbox {
background-color:#FFFFFF;
font-size:80;
height:100;
color: black;
font-weight:bold;
text-align: center;
width:950;
}
.detailbox {
height:80;
font-size:50
}
sup {font-size:40; vertical-align:top; position:relative; top:-5}
#quest{
font-size:20;
text-align:right;
border-style: solid;
border-color: gray;
border-width: 1;
width: 130
}
</style>
<script>
function power(arr)
{
newarr=new Array()
for(k=0; true; k++)
{
base=arr[0]
for (expo=1; arr[expo]==base;expo++){}
newarr[k]=base+(expo!=1 ? "<sup>"+expo+"</sup>" : "")
if (expo>=arr.length) {break}
arr=arr.slice(expo)
}
return newarr.join("×")
}
function twodivisors(numb)
{
for (var i=2; i<=Math.sqrt(numb); i+=1)
{
if (numb%i==0) {return new Array(i,numb/i)}
}
return "pr"
}
function analyze(num)
{
iffalse=detailsplace+"=num+'='+power(primedivisors);"+yesnoplace+"='Number '+num+' is not prime'"
iftrue=yesnoplace+"='Number '+num+' is prime'"+detailsplace+"=''"
if (num<2) {eval(detailsplace+"=''"+yesnoplace+"='Number '+num+' is not prime'"); return}
if (num==2) {eval(iftrue); return}
if (num%2==0)
{
primedivisors=new Array()
primedivisors.push(2)
for (otherdivisor=num/2; twodivisors(otherdivisor)!="pr"; otherdivisor=twoparts[1])
{
twoparts=twodivisors(otherdivisor);
primedivisors.push(twoparts[0]);
}
primedivisors.push(otherdivisor)
eval(iffalse); return
}
for (var i=3; i<=Math.sqrt(num); i+=2)
{
if (num%i==0)
{
primedivisors=new Array()
primedivisors.push(i)
for (otherdivisor=num/i; twodivisors(otherdivisor)!="pr"; otherdivisor=twoparts[1])
{
twoparts=twodivisors(otherdivisor);
primedivisors.push(twoparts[0]);
}
primedivisors.push(otherdivisor)
eval(iffalse); return
}
}
eval(iftrue); return
}
function starter()
{
num=document.formh.quest.value
if (isNaN(num)) {alert("You entered an invalid number."); return}
detailsplace="document.getElementById('details').innerHTML"
yesnoplace="document.getElementById('answer').innerHTML"
analyze(eval(num))
}
</script>
<div class=answerbox id=answer></div>
<div class=detailbox id=details></div>
<form name=formh>
Number: <input type=text id=quest><br>
<input type=button value="Is it prime?" onClick=starter()><br>
</form>
View 2 Replies
View Related
Nov 19, 2009
I have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads.[code]...
View 1 Replies
View Related
Nov 19, 2009
I have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads.code...
View 1 Replies
View Related
May 1, 2009
i'm creating a ASP page, which is going to have a form in it that needs filling out. part of the form will be a table with a header row, then the next rows will have text boxes that need filling out. is there a way of putting in a dropdown box that contatins numbers that will dynamically show the rows. for example if i select 5, then five rows of text boxes will appear. if i select 14 then 14 appear.
View 3 Replies
View Related
Nov 15, 2011
I have this code for figuring out whether a given number is prime or not:
var SMALLEST = 2;
var BIGGEST = 9E15;
var n = prompt("Enter a number and I'll check if it is prime");
if (isNaN(n) || n < SMALLEST || n > BIGGEST || n % 1 !== 0) {
alert("I can only test integers between " + SMALLEST + " and " + BIGGEST);
[Code]...
View 2 Replies
View Related
Apr 7, 2009
I need to modify the script showed at: [URL]
Right now it allows entering "numbers only", I need it so that it allows numbers and alphabets only, no special characters or spaces.
And yes, one more question, does the first part of the code need to be added in the <head> of the document or <body> ?
The code at the above URL is as follows:
<script type="text/javascript">
// initialise variable to save cc input string
var cc_number_saved = "";
</script>
[Code].....
View 2 Replies
View Related
May 10, 2006
i've been reading up on access to the dom via js (i'm new to this dom
stuff)
i understand tutorials and info such as
http://developer.mozilla.org/en/doc...t.createElement
my problem: i'd like js to create the code for a stylesheet in the head
of the docuement!
i'm not sure how do do this (or if it can be done)
can i create the following...
<link rel="stylesheet" type="text/css"
href="mystyle.css" />
OR
<style type="text/css">
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif")}
</style>
using the dom or anything else in js alone?...or am i fighting a losing
battle.
(what i really want at the end of the day is to detect the browser and
use a css file according to that file, either with js or php)...
View 3 Replies
View Related
Jul 20, 2005
I there any way for javascript to write/manipulate a file other than through a cookie?
View 1 Replies
View Related
Jul 20, 2005
I have an existing page that dynamically creates data in a popup
window. I am trying to change it to use an iFrame. Is the following
code valid:
The iFrame is as follows
<iframe src="theframe.html" name="theframe"></iframe>
"theframe.html" is an existing file initially with instructions.
In a script I do
thewindow=window.open("","theframe");
thewindow.document.open();
thewindow.document.write("Some Requested Data");
thewindow.document.close();
This is done multiple times depending on what the user requests each
time. Sometimes this works and sometimes it doesn't. I'm probably doing
someing very wrong but I don't know where to look for reference.
I'm not really opening a window so there must be another way to do it.
What is the best way to write to an iFrame or should I not even try?
Code:
View 2 Replies
View Related
May 31, 2009
I am "writing" a javascript function to my page with php:
<html>
<head>
<title>Just about everything</title>
[code]....
View 4 Replies
View Related
Dec 23, 2009
I need to reset the active content registry entries to the defaults when a page unloads:
<script>
// Window Onunload, last to execute, manage registry
function windowonunload(){
var WshShell = WScript.CreateObject("WScript.Shell");
[Code]....
View 2 Replies
View Related
Dec 3, 2010
I'm struggling to find out why the iframe is not being populated with a selectbox containing the album names from an XML file. majority of the code is working fine and the "alert(s)" function works perfectly and displays exactly the html I would like it to but the bits in bold are not working and are not writing the html to the iframe.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
[code]....
View 2 Replies
View Related
Nov 19, 2007
I'm using this to write html tag in me textarea. Now i'm wondering what code do i need to use so that text cursor stays in textarea after i click on the button so that i don't have to click back to textarea every time i press button. Code:
View 6 Replies
View Related
Jun 28, 2001
I have a function that generates the code I want from form input.
Beneath the form I want to create a div tag and write out the results from the form input.
How would I go about doing this?
How would I go about passing the results from the function (e.g. function newCode() {.......(code)... var scroll = X }
Then I want to write out X in a div tag?
View 11 Replies
View Related
Apr 28, 2006
Does anyone know where i can find a tutorial on how to change the content of a layer like this: Writing to layers.
View 1 Replies
View Related
Jan 7, 2010
I'm trying to write a Tic-Tac-Toe program in JavaScript. I have an array containing the state of the grid. For some reason when I update the "O" for the computer's move, it doesn't show this in the updated grid. I don't understand why.[URL].. I'm brand new to JavaScript, and sometimes I accidentally use syntax from C++ or PHP when writing, so it could be something as simple as that. I just can't figure it out.
[Code]...
View 3 Replies
View Related
Jul 23, 2005
I have an HTML page with 3 frames. Lets call them top middle and bottom.
On the top frame there is a button to run some java script! When it is run
I want to put some text into the middle frame, but in to a text box on a
form call "testform" textbox name is "TestText"
I know I need to address the frame name but what am I missing?
Parent.frames("middle").TextText.value = "here is the data"
View 1 Replies
View Related
Jul 23, 2005
I trying to but buttons for the users to write special characters to a text area in a form by clicking in a button.
<form name="form1" onSubmit="return (function1() && function2() &&
function3();">
<textarea name=t1> </textarea>
<input type=submit value="ƒ">
<input type=submit value="¼">
<input type=submit value="÷">
<input type=submit value="µ">
</form>
<script language="JavaScript"><!--
function functionName1() {
window.document.form1.t1.value = 'ƒ'
return false;
}
function functionName2() {
window.document.form1.t1.value = '¼'
return false;
}
function functionName3() {
window.document.form1.t1.value = '÷'
return false;
}
function functionName4() {
window.document.form1.t1.value = 'µ'
return false;
} //--></script>
Clicking on any button doesn't do anything but if I put just one button it works, can anyone suggest what did I do wrong?
View 2 Replies
View Related
Oct 11, 2005
i have a page called 'a.php'. on this page is a form with a textfield and a link.
if you click the link an pop up opens. in this pop up is an number visible with a link.
what i want is this:
when you click the link in the pop up, the number from the pop up must appear in the textfield from page a.php.
i tried:
a javascript under the link in the pop up with:
function brinnummer(nummer){
document[0].getElementById('brinnummer')[0].value = nummer;
}
but it doesnot work.
View 3 Replies
View Related
Apr 1, 2007
I need a row of tickertape. Each character should appear on screen as
if it were being typed, so that the entire row is scrolled left to
right. Like a 'teletype' - I think they were called. Code:
View 5 Replies
View Related
Jul 20, 2007
I'm not that familiar with javascript, and I am trying to write a
toFixed function.
The function takes two arguments, the number and the number of decimal
places we're interested in.
If the number of decimal places is negative, it's interpreted as the
number of significant digits.
Thus:
toFix(12345.6789,2) -12345.67
toFix(12345.6789,0) -12345
toFix(12345.6789,-2) -12000
I've hacked up a solution that so far works on all tested browsers for
the first 2 cases.
It's the last one I'm having trouble with... How do I get only the
significant digits?
It has to work for all of the following cases:
toFix(12345.6789,-2) -12000
toFix(12345.6789,-5) -12345
toFix(12345.6789,-7) -12345.67
View 2 Replies
View Related