Displaying List Of Prime Numbers Only

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


ADVERTISEMENT

Displaying First 1000 Prime Numbers In Table

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

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 View Related

Select Numbers From List And Add To Text Box

Jun 12, 2010

I want to select numbers from a list box and add it to a text box with comma separated. my java script code does not work into browser but work fine into eclipse jsp view.

function passingNumbersToTextArea(numToCall,allNum)
{
var numFromList=document.getElementById(allNum);
var numToTextArea=document.getElementById(numToCall);
if(numToTextArea.value.search(numFromList.value)!=-1)//if duplicate Number is exist
{
alert("Duplicate Number Can not be added :");
return false;
}
else
{
if(numToTextArea.value.length!=0)
{
// If textarea has value than it added another value with comma seperated
numToTextArea.value=numToTextArea.value+','+numFromList.value;
return false;
}
else
{
numToTextArea.value=numFromList.value;
return false;
}
}
}

jsp code
<h:inputTextarea cols="10" rows="4" id="numberToCall" required="true"
value="#{conferenceCall.numberToCall}" styleClass="form_input_box" />
<h:selectOneListbox styleClass="form_selectmenu" id="allNumbers" size="5" onclick="passingNumbersToTextArea('numberToCall','allNumbers');">
<f:selectItem itemValue="9971701077" itemLabel="Sharad : 9971701077"/>
<f:selectItem itemValue="9990102381" itemLabel="Saurabh : 9990102381"/>
</h:selectOneListbox>

javascript debugger shows error
Error ``numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServiceProvisioningSystem/home.jsf'', line 21, character 0.
Exception ``TypeError: numToTextArea is null'' thrown from function passingNumbersToTextArea(allNum=string:"allNumbers", numToCall=string:"numberToCall") in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 21.
[e] message = [string] "numToTextArea is null"
Exception ``TypeError: numToTextArea is null'' thrown from function onclick(event=MouseEvent:{0}) in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 1.
[e] message = [string] "numToTextArea is null"
Error ``TypeError: numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServiceProvisioningSystem/home.jsf'', line 21, character 0.

View 4 Replies View Related

Displaying A List Of Pictures?

Jul 23, 2005

I have this list of pictures;

<script type="text/javascript">
var picssigs = new
Array("sigs/finished1.jpg","sigs/foghorn.jpg","sigs/motto.jpg","sigs/sig.jpg","sigs/SWAT.jpg","sigs/title.gif");
var pictsigs = Math.round(Math.random()*(picssigs.length-1));
for (var i=0; i<picssigs.length; i++) {
var imgsigs = new Image();
imgsigs.src = picssigs[i];}

How do I display these pictures like;

<pic1> <pic2> <pic3> ...etc...
<pic4> <pic5> ...etc...

View 3 Replies View Related

Prime Or Not.

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

Adding To A List Box And Displaying In A Text Box?

Apr 20, 2011

I am having trouble adding to my option box, I want to add the name "Angie" to my select list and display it in the text box as well using a new function. I am not sure what the proper code is to do this. The rest of my program is working with no errors. Is there a form that shows how to do this? Below is my code the part I am having trouble with says add your name and should work with button b5 on click.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Javascript Test 2</title>
<script type="text/javascript">

[Code]....

View 3 Replies View Related

Making Ordered List Numbers With Onclick Display Prompt?

Feb 13, 2009

Is is possible to make an ordered list with an onclick display prompt show the number item of the list? What I mean is like, say I have 29 items, but I click on item 15, is possible to make the prompt show the number 15, or the correct number for any item I pick?

View 2 Replies View Related

Displaying Part Of Form Based On List Box Selection

Mar 13, 2006

I have a form with a drop down list box, few textboxes with labels and submit button. depending upon my selection I should be able to show hide textbox; assume items, 1,3,5 in the selection box shows the items other than the listbox and 2,4,6 items in the selction box if selected hides the labels and textboxes. but in all the case submit button should be present.

View 6 Replies View Related

Jquery :: Navigation List Items Displaying Inline

Aug 22, 2011

I am trying to make a drop down menu in JQuery and I have hit a roadblock. I have been trying for hours to work this out myself but I'm coming up with nothing. The problem is that my dropdown items are displaying horizontally instead of vertically, here is the code:

HTML Code:
<nav class="ribbon">
<ul>
<li class="dropdown">
<a href="#" class="nav"><h1>Home</h1></a>
<ul>
<li><a href="#"><h2>Page 1</h2></a></li>
</ul>
</li> .....

View 1 Replies View Related

Ask For Integer Then List Numbers To That Integer On Page!

Sep 13, 2006

I am trying to learn how to do this one thing with JavaScript and can't seem to find anything on the internet. I have learned about loops and arrays and some other useful stuff. I've been looking for 2 days straight. I have gotten close though.

I am trying to have a textbox on the page and a button below it. A statement above the textbox should ask the user to enter a positive integer and then click the button. When the button is clicked the results from 0 to that number should appear below the button. Should look like this

please enter positive integer.
6
BUTTON1

1
2
3
4
5
6

I have been trying night and day for 2 days now and It's driving me insane.

View 8 Replies View Related

"speed Up" Prime # Test Script With These Modifi?

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

Include Numbers And Alphabets Instead Of Numbers Only?

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

Multiple Drop Down With Dynamic List (PHP - MySql - AJAX) - Filter The Results Into A List

Aug 2, 2011

I have a table that has parts with multiple characteristics. Part Number, Height, Width, Capacity, Price, Etc. I would like to have a drop downs for all of these values, when a user selects one of these values it will filter the results into a list. Ex. user selects a part that has a Height of 6 and width of 10 it will only list those parts. As I said earlier, I have a script that will give me all the parts, however I am not able to make the onchange list parts with multiple values.

View 9 Replies View Related

JQuery :: Limit If A Value Can Be Selected In A Drop Down List (select) Based On Other List

Jun 9, 2009

I have a page that displays a list of people playing in a tournament. I need to be able to generate a Leaderboard based on which players are manually selected by the admin. Next to each person there is a drop-down list. An admin can go in and select a "slot" that a player should be in on the leader board from 1 to 8, or leave it blank if none. What I need to figure out how to do is the following, when a change event happens on a drop-down list, and say the value 5 is selected, I need to check to make sure that 5 is not already selected in one of the other players drop-down lists, in other words, that the 5th leaderboard slot is not already full. if it is, display an error message and make them change that one first. how to do that with jQuery? I'm thinking it will have something to do with the each() function, but not sure exactly how the logic should work.

View 4 Replies View Related

JQuery :: Access The 'a Href' In A List Item In An Unordered List??

Oct 8, 2010

i have a menu and i would like to change the color of the Categories which have subcategories only. In my example the basic categories are: News , Announcements , Contact and Career. Only Announcements and Career categories have subcategories. So i would like those two to turn green. The fact is that the list items include a href ,so i don't know how to access those "a href" combined with "this".

<ul id="my_menu">
<li id="id0"><a href="#" style="text-decoration:none">News</a></li>
<li id="id1"><a href="#" style="text-decoration:none">Announcements</a>
<ul>

[Code].....

View 3 Replies View Related

JQuery :: Simple Expand/collapse List : Big Gap Of Space After The List?

Jun 2, 2010

I have been trying to make an expand/collapse (essentially accordion) list. So far, everything works and looks fine in Firefox, Safari, and Chrome, but in IE8, the page height is static when it loads, with a page height being as if all headers in the list were expanded. The expand/collapse functionality works,but as you can imagine, there is this big gap of space after the list.

The html markup uses <h2> tags for the always-visible header portion and a <div> for the expanding/collapsing content. The <div> content contains form elements and everything is enclosed in a form tag.Anyways, here is the jQuery code:

$(document).ready(function() {
$('<img src="plus.png" class="icon" />').prependTo('.header');
$('.content').hide();[code].....

View 5 Replies View Related

Update A Dropdown List Based On The Selection Of A Previous List

Aug 16, 2010

i am writing a script that will update a dropdown list based on the selection of a previous list. the script is run by a PHP script, so instead of posting the PHP, i will post an example client-side script. the hierachy is: category, sub category, brand (but sometimes there exists no sub category and the PHP script queries and adds brands instead) everything works correctly, except for one major issue: you can not change the selection of the third (brand) box this could be an easy fix for some coders, but i am not experienced in javascript and could really use some help. here is an example script, sorry it is so long

[Code]...

View 4 Replies View Related

PHP Drop Down List Selection Populates Second Dropdown List Or Text Box?

Jul 13, 2011

I have been struggling on a bit of code for a while now. I need to populate a second drop down list (Region) based upon the selection of the first (County).I have found a piece of code that works on its own and have adapted to suit my needs - see below. However, when I drop it into my main page the javascript is not working. It's because of the formObject but I just don't know enough to resolve this! Furthermore, I need the textboxes the user has already completed in the form to retain their value once the javascript kicks in as the completed form will submit to a database.This piece of code is working well . . . .

<?php

$link = mysql_connect('myhost', 'myusername', 'mypassword') or die('Could not connect: ' . mysql_error());
mysql_select_db('mydatabase') or die('Could not select database');[code]......

View 2 Replies View Related

AJAX :: Populate An ASP List Box Based On Selection Of A Previous List Box?

Mar 7, 2011

I have 3 ASP list boxes. I would like to populate the second list box based on the selection in the first list box and based on the selection in the second list box, populate the third. I would like to do this using AJAX. How can I do it? Can someone please give me the code snippet as I am a complete noob when it comes to AJAX and I kinda am running outta time to finish implementing it. Additionally, should I use ASP boxes or HTML <select> tag?

View 4 Replies View Related

JQuery :: Inserting A List Element Into An Ordered List?

Jul 19, 2010

I'm working on a project that requires dynamic manipulation of an ordered list -- adding and removing elements in response to the user pressing buttons. I've run in to some odd behavior. Here's my code:

HTML

<ol id="track-list">
<li>Static Content Here</li>
</ol>
<input type="button" id="add-track" value="Add Track" />

jQuery:

$("#add-track").click(function(){
var listEl = $("<li>Dynamic Content Here</li>");
listEl.hide();

[code]....

Looks pretty straightforward, problem is when I add the new list element it does not prepend it with any number (being part of an ordered list). Now if I remove the hide and fadeIn lines (just append it), it inserts it correctly with a number before it, but I want this to look pretty being jQuery and all...

View 3 Replies View Related

Jukebox - Replay List And - Create Non Dropdown List ?

Sep 1, 2010

I am trying to construct a Jukebox for my website. I have spent considerable time all over the WEB and at this forum which addressed the issue in a 50 page thread. Please see: [url]

I got a lot of ideas from this thread but still cannot figure a way to do the following within the Jukebox. These are my main two questions for everything below:

1.How can I have the Jukebox cycle through all tunes and then start over from the beginning?

2.How can I allow the user to select a tune from a list but not a drop down list, have the Jukebox start from the users selection and then play all songs to the end. Then as in #1, start over from the beginning?

Per this thread I came away with basically two ways to assemble the jukebox. One uses links in a drop down list which the user can choose from. The other is to use an .m3u playlist. The user can only select a playlist from the drop down.

Below, I have included the code for each Jukebox. To see the Jukeboxes in action please go to my website where I have posted some test pages exhibiting the jukeboxes that I am referring to.

The following is the Jukebox which utilizes an .m3u playlist. If I end up using this idea I would like the tunes in the .m3u playlist to be displayed and allow the user to be able to choose a tune in the list. Then have the list play to the end of all tunes in the list. Then start over from the beginning of the list. After this code is the .m3u playlist.

Go to url removed and click on the link that says:

Jukebox utilizing an .m3u playlist:

Here is the .m3u playlist for the above code:

The following code is for the Jukebox that has a list of links in a dropdown list. If I go with this idea, I would like for the list not to be a dropdown list but just a list of tunes. The user should be able to click on any tune in the list and the player should start from that point, play all the remaining tunes in the list and then start from the beginning.

Go to url removed and click on the link that says:

Another idea I found on the WEB also uses an .m3u playlist. The good thing about it is that it lists all the tunes in the playlist which the user can then select from. This jukebox calls up an entire Windows Media Player. If I was to use this idea I would like to be able to disable the left side of the player where the user has options such as burning to CD, Media Guide, Radio Tuner etc¦

Go to url removed and click on the link that says:

View 1 Replies View Related

Transfer Data From Popup List Box To Parent List Box

Jul 6, 2004

when i try to add a data from popup list box to parent window listbox it pops an error.
Servlet threw an exception. This is my code

var optionvalue=thisForm.behaviourname.options[i].value;
var len=window.opener.document.FormMaterialDetail.inparameterid.options.length; window.opener.document.FormMaterialDetail.inparameterid.options[len] = new Option(thisForm.behaviourname.options[i].text, optionvalue);

Is the above code right?

View 1 Replies View Related

JQuery :: Select A Sub-list From A Long List?

Aug 14, 2009

I have a MySQL table with 90 columns and I want the users to be able to select any columns they concern and output the result accordingly. In the front-end, I can use a group of checkbox which looks very ugly and I can not setup the orders for selected columns. Is there a plug-in or some examples in jQuery, that I can make 2 parallel boxes (i.e. an original-box and a selected-box). the original- box lists all of the column names at the beginning and there is a way to move items between two boxes. And the order of items in the selected-box can be adjusted. the items in the selected-box will be used to build into an array in my backend code.

View 1 Replies View Related

JQuery :: Wrapping A Portion Of A List Within A List?

May 21, 2011

I am trying to wrap a list with in a list. I am not able to achive this. Here is the html markup:

<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>

[Code]...

View 4 Replies View Related

Get The Order Of List Item In An Unordered List?

Feb 17, 2009

I am trying to get the order of list item in an unordered list. Here is the mark up

Code HTML4Strict:
<ul id="list1">
<li>ul1 item 3</li>
<li>ul1 item 2</li>
<li>ul1 item 1</li>
</ul>

[Code]...

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved