www.webdeveloper.com
Results 1 to 6 of 6

Thread: How to look certain values from javascript table

  1. #1
    Join Date
    Nov 2010
    Posts
    3

    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).

    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.)

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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.
    Last edited by Kor; 11-08-2010 at 02:18 PM.

  3. #3
    Join Date
    Nov 2010
    Posts
    3
    How can I use simple if(){} statement? (Can not be googled.)
    is it something like:

    PHP Code:
    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
    (And it may not be unique, but that can be forgotten.)

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by CaesarTapsa View Post
    How can I use simple if(){} statement? (Can not be googled.)
    is it something like:

    PHP Code:
    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
    (And it may not be unique, but that can be forgotten.)
    OK. You have just used a "simple if(){} statement". So? Which is the problem?

  5. #5
    Join Date
    Nov 2010
    Posts
    3
    I changed my code a lot and here is some parts of it:

    PHP Code:
    <FORM NAME lom0>
    <
    table width="800"><tr>
    <
    td>ID6</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>ID7</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>ID8</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
    PHP Code:
    <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)
    = (pisteet[j][3] - pisteet[i][3])
    = (pisteet[j][2] - pisteet[i][2])
    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">
    &
    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
    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.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    if(pisteet[i][0] != p1)
    if(pisteet[j][0] != p2)
    Where are those variable defined? Do you intend to perform a loop?:
    http://www.w3schools.com/JS/js_loop_for.asp

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles