//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).
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.
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.)
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
Code:
while(pisteet[j][0] = p2)
will not return a Boolean unless the second term is undefined/false/null (which is not your case). I guess you need a comparison operator:
Code:
while(pisteet[j][0] == p2)
But, as this possibility is unique, I don't sense whay you have not used a sinple if(){} 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:
Code:
while(pisteet[j][0] != p2)
As I said, I don't understand very well your aim... Nor your syntax.
<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 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>
PHP Code:
<FORM NAME = lom1>
Pisteen 1 ID: <INPUT TYPE = Text NAME = piste1 SIZE = 5 value ="6">
Pisteen 2 ID: <INPUT TYPE = Text NAME = piste2 SIZE = 5 value ="8">
<P>
Matka 1→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>
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, I'd like to search exact cell row which has its [n][0] value same as what user will type into form box "piste1" (or "piste2"). if(pisteet[i][0] != p1) seems unable to do it.
Last edited by CaesarTapsa; 11-09-2010 at 03:04 PM.
Reason: Clarifying.
Bookmarks