/    Sign up×
Community /Pin to ProfileBookmark

How to look certain values from javascript table

I’m sorry I don’t know how to put my code in PHP block.

</br>
<PHP>
//Here I have part of my javascript table
pisteet[6][0] = prompt(“Tunnistenumero:”, “3”)
pisteet[6][1] = prompt(“Tunnistenimi:”, “1”)
pisteet[6][2] = Number(prompt(“X-koordinaatti:”, 4572))
pisteet[6][3] = Number(prompt(“Y-koordinaatti:”, 1654))
pisteet[7][0] = prompt(“Tunnistenumero:”, “15”)
pisteet[7][1] = prompt(“Tunnistenimi:”, “1”)
pisteet[7][2] = Number(prompt(“X-koordinaatti:”, 8442))
pisteet[7][3] = Number(prompt(“Y-koordinaatti:”, 5624))
pisteet[8][0] = prompt(“Tunnistenumero:”, “21”)
pisteet[8][1] = prompt(“Tunnistenimi:”, “1”)
pisteet[8][2] = Number(prompt(“X-koordinaatti:”, 3214))
pisteet[8][3] = Number(prompt(“Y-koordinaatti:”, 9846))

//My purpose is to search two prompted points from the table above.
var p1 = prompt(“Piste 1 suuntakulman ja matkan laskemista varten:”, 3)
var p2 = prompt(“Piste 2 suuntakulman ja matkan laskemista varten:”, 21)
//No, those numbers aren’t really numbers so I am not looking for numbers in the table.

//Following do-while searches doesn’t work because they look numbers?
i=1
do
{
i++;
if(i == 100) break;
}
while(pisteet[i][0] = p1)

j=1
do
{
j++;
if(j == 100) break;
}
while(pisteet[j][0] = p2)
//So I want to input any two point number (Tunnistenumero) in promt p1 and p2 and calculate difference in Y-coordinates.

var etaisyys = ((pisteet[j][3]-pisteet[i][3]))
document.write(“<p>joo “,etaisyys,” “,pisteet[i][3]);
//pisteet[i][3] should write 1654
</PHP>
</br>

It might help you if I would upload the whole javascript, but as you requested, I didn’t.

So, basically I have a table of points with coordinates and I want to calculate difference in Y-coordinates between any of them.
I want to search points by their name (point numbers/tunnistenumero).

[B]I’ll try to make it more clearer:

Question: pisteet[?][0] = “3”
Answer should be: pisteet[6][0] = “3”

With above question how I can get above answer in javascript?
The rest I can do by myself.[/B]

Did you get what I want to do with javascript? (Because I doubt that you got it, but I did my best at pointing out the question so if nobody understands what I try to do, then never mind.)

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 08.2010 — quite muddy your code. At a first glance, I can note that document.write() is not a dynamic method.

On the other hand, a conditional while loop must have a Boolean as condition. A simple assignment like
<i>
</i>while(pisteet[j][0] [COLOR="Red"]=[/COLOR] p2)

will not return a Boolean unless the [I]second[/I] term is undefined/false/null (which is not your case). I guess you need a [I]comparison[/I] operator:
<i>
</i>while(pisteet[j][0] [COLOR="Blue"]==[/COLOR] p2)

But, as this possibility is unique, I don't sense whay you have not used a sinple [B]if(){}[/B] statement. Or a switch/case one. Or probably you want to loop the array till both terms are the same. In this case, probably you need:
<i>
</i>while(pisteet[j][0] [COLOR="Blue"]!=[/COLOR] p2)


As I said, I don't understand very well your aim... Nor your syntax.
Copy linkTweet thisAlerts:
@CaesarTapsaauthorNov 09.2010 — How can I use simple if(){} statement? (Can not be googled.)

is it something like:

[code=php]
pisteet[8][0] = prompt("Tunnistenumero:", "21")

var p2 = prompt("Piste 2 suuntakulman ja matkan laskemista varten:", 21)

if(pisteet[j][0] == p2){j=8}

var etaisyys = ((pisteet[j][3]-pisteet[i][3]))
document.write(etaisyys)
[/code]


(And it may not be unique, but that can be forgotten.)
Copy linkTweet thisAlerts:
@KorNov 09.2010 — [COLOR="Red"]How can I use simple if(){} statement[/COLOR]? (Can not be googled.)

is it something like:

[code=php]
pisteet[8][0] = prompt("Tunnistenumero:", "21")

var p2 = prompt("Piste 2 suuntakulman ja matkan laskemista varten:", 21)

if(pisteet[j][0] == p2){j=8}

var etaisyys = ((pisteet[j][3]-pisteet[i][3]))
document.write(etaisyys)
[/code]


(And it may not be unique, but that can be forgotten.)[/QUOTE]


OK. You have just used a "simple if(){} statement". So? Which is the problem?
Copy linkTweet thisAlerts:
@CaesarTapsaauthorNov 09.2010 — I changed my code a lot and here is some parts of it:

[code=php]
<FORM NAME = lom0>
<table width="800"><tr>
<td>ID: 6</td>
<td>Piste: <INPUT TYPE=Text NAME=syo60 SIZE=4 value="6"></td>
<td>Kuvaus: <INPUT TYPE=Text NAME=syo61 SIZE=12 value="Tasokiintopiste"></td>
<td>X: <INPUT TYPE=Text NAME=syo62 SIZE=10 value="4572.000"></td>
<td>Y: <INPUT TYPE=Text NAME=syo63 SIZE=10 value="1654.000"></td>
<td>Z: <INPUT TYPE=Text NAME=syo64 SIZE=7 value="0.000"></td></tr><tr>
<td>ID: 7</td>
<td>Piste: <INPUT TYPE=Text NAME=syo70 SIZE=4 value="7"></td>
<td>Kuvaus: <INPUT TYPE=Text NAME=syo71 SIZE=12 value="Tasokiintopiste"></td>
<td>X: <INPUT TYPE=Text NAME=syo72 SIZE=10 value="8442.000"></td>
<td>Y: <INPUT TYPE=Text NAME=syo73 SIZE=10 value="5624.000"></td>
<td>Z: <INPUT TYPE=Text NAME=syo74 SIZE=7 value="0.000"></td></tr><tr>
<td>ID: 8</td>
<td>Piste: <INPUT TYPE=Text NAME=syo80 SIZE=4 value="8"></td>
<td>Kuvaus: <INPUT TYPE=Text NAME=syo81 SIZE=12 value="Tasokiintopiste"></td>
<td>X: <INPUT TYPE=Text NAME=syo82 SIZE=10 value="3214.000"></td>
<td>Y: <INPUT TYPE=Text NAME=syo83 SIZE=10 value="9846.000"></td>
<td>Z: <INPUT TYPE=Text NAME=syo84 SIZE=7 value="0.000"></td></tr><tr>
</table><hr>
</FORM>
[/code]
[code=php]
<script type="text/javascript">
var pisteet = new Array(11)
pisteet[0] = new Array(4)
pisteet[1] = new Array(4)
pisteet[2] = new Array(4)
pisteet[3] = new Array(4)
pisteet[4] = new Array(4)
pisteet[5] = new Array(4)
pisteet[6] = new Array(4)
pisteet[7] = new Array(4)
pisteet[8] = new Array(4)
pisteet[9] = new Array(4)
pisteet[10] = new Array(4)

function otapis() {

pisteet[6][0] = document.lom0.syo60.value
pisteet[6][1] = document.lom0.syo61.value
pisteet[6][2] = document.lom0.syo62.value
pisteet[6][3] = document.lom0.syo63.value
pisteet[7][0] = document.lom0.syo70.value
pisteet[7][1] = document.lom0.syo71.value
pisteet[7][2] = document.lom0.syo72.value
pisteet[7][3] = document.lom0.syo73.value
pisteet[8][0] = document.lom0.syo80.value
pisteet[8][1] = document.lom0.syo81.value
pisteet[8][2] = document.lom0.syo82.value
pisteet[8][3] = document.lom0.syo83.value

}

function matka() {
p1 = document.lom1.piste1.value
p2 = document.lom1.piste2.value
if(pisteet[i][0] != p1)
if(pisteet[j][0] != p2)
A = (pisteet[j][3] - pisteet[i][3])
B = (pisteet[j][2] - pisteet[i][2])
C = Math.sqrt(A*A+B*B)
document.lom1.eta.value = C
}
</script>
[/code]
[code=php]
<FORM NAME = lom1>
Pisteen 1 ID: <INPUT TYPE = Text NAME = piste1 SIZE = 5 value ="6">
&nbsp;&nbsp;&nbsp;Pisteen 2 ID: <INPUT TYPE = Text NAME = piste2 SIZE = 5 value ="8">
<P>
Matka 1&#8594;2: <INPUT TYPE="Text" NAME="eta" SIZE=5 value="">
<P>
<Input Type="Button" NAME="b1" VALUE="Laske suunta ja matka" onClick="otapis();matka()">
</FORM><hr>
[/code]


Nothing comes into answer form box.

I got this working by referring to "ID:" from the table instead of referring to "Piste:"

But because "ID:" and "Piste:" can be different, [B]I'd like to search exact cell row which has its [[I]n[/I]][0] value same as what user will type into form box "piste1" (or "piste2").[/B] if(pisteet[i][0] != p1) seems unable to do it.
Copy linkTweet thisAlerts:
@KorNov 10.2010 — <i>
</i>if(pisteet[[COLOR="Red"]i[/COLOR]][0] != p1)
if(pisteet[[COLOR="Red"]j[/COLOR]][0] != p2)

Where are those variable defined? Do you intend to perform a [I]loop[/I]?:

http://www.w3schools.com/JS/js_loop_for.asp
×

Success!

Help @CaesarTapsa 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...