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 03: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 04: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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15804 seconds
  • Memory Usage 2,974KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates