Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2006
    Posts
    10

    Question Unanswered: passing php variables with javascript?

    I am trying to open a small new window using javascript and pass a php
    variable onto the new window and this is really being a pain. I believe
    that this is possible but everything that I have tried so far has not
    worked. The relevant code that I am usiing is below. The problem is the
    variable $aster resides in a cell of a table that displays notes
    pertaining to a specific item and depending on the item the notes could
    change. Each table may have anywhere from 1 to 10 notes and they are
    all different. I had everything working fine opening another window
    without javascript but a smaller window would suffice. As of now, all
    of the notes are the same and it is always the last set of notes in the
    table. Anyone familiar with this? Any help would be greatly
    appreciated.


    <SCRIPT language="JavaScript">
    <!--hide
    function newwindow
    {
    window.open('cust_parts_notes.php?aster=<?print
    ($aster);?>','Notes','width=400,height=400,resizab le=yes');
    }
    //-->
    </SCRIPT>
    <tr bgcolor=white><td align="center"><?echo "$qty";?></td><td><?echo
    "$partnum";?></td><td><?echo "$desc1 $desc2"?></td>
    <?
    if ($yes_no == "Y"){
    ?><td><a href="javascript:newwindow'<?print ($aster);?>')"
    title='<?echo "$aster"?>'>Notes</a></td><?
    } else { ?><td> </td><?
    }
    ?>
    </tr>
    <?
    }
    }
    odbc_close($connect);
    ?>
    </body>
    </html>

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    im not too sure what you are trying to do....

    Javascript can be a bit flaky depending on the version, the browser and seemingly the time of day

    for an anchor I recently used an onclick event similar to:-

    <a class=\"#classname#\" onclick=\"#Javascriptfuctionname#('#classname#');\ "><span id=\"#elementname#\">#somedata#</span></a>";
    note this code has been culled to remove sensitive settings from a site so it may include typos & errors
    replace the text in the # with the relevant data element

    having trapped the event with a Javascript function, if you pass the calling row as part of the parameters you cna then do what ever you want on the client.

    HTH
    Javascript.....yuck
    good luck
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    I cannot tell what you are doing either, but the value in the PHP variable $aster would be the value at the time the web page was sent to the browser. By placing this in the javascript function code, that code will always operate on that single value.

    If you want the code in each table row to call the javascript function and pass it the value that is in that row (which is how it looks you have the table code written to do), you need to define your javascript function to accept a parameter in the function call and then use that parameter within the code in the function.

  4. #4
    Join Date
    Oct 2006
    Posts
    10

    Exclamation php and java??

    Here is all the code associated with what I am trying to accomplish. I am extracting a complete order from an AS400 db using search criteria specified by an html form. The notes are specific to various part numbers on the order. As of now, I have the notes echoing through the "title" of the hyperlink when you hold the mouse on the link. This works great for short notes that can be read in the time frame in which the "title" stays on the screen but for longer notes, I wanted to open a seperate window so that the viewer can read the notes. It seems that the only way to open a smaller window and not totally block the entire screen is to use java... Any suggetsions??


    <TABLE border=1>
    <tr bgcolor="#C0C0C0"><th>Quantity</th><th>Part Number</th><th>Description</th><th>Notes</th></tr>
    <?
    $i = 1;
    $check = "";
    $query1 = "SELECT sdlitm, sddsc1, sddsc2, sduorg, sdatxt, sdlnid FROM F4211 WHERE sddoco = $order AND sddcto LIKE '$ordertype' ORDER BY sdlnid";
    $result1 = odbc_exec($connect, $query1);
    while (odbc_fetch_row($result1)){
    $partnum = odbc_result($result1, 1);
    $desc1 = odbc_result($result1, 2);
    $desc2 = odbc_result($result1, 3);
    $qty = odbc_result($result1, 4)/100;
    $yes_no = odbc_result($result1, 5);
    $position = odbc_result($result1, 6);
    if ($yes_no == "Y"){
    $notetext = '';
    $query2 = "SELECT jmtxln FROM F4314 WHERE jmdoco = $order AND jmdcto LIKE '$ordertype' AND jmlnid = $position ORDER BY jmlins";
    $result2 = odbc_exec($connect, $query2);
    while (odbc_fetch_row($result2)){
    $notes = odbc_result($result2, 1);
    $notetext = ($notetext . $notes . "\n");
    $aster = str_replace("*", "", $notetext);
    $aster = ltrim($aster);
    $aster = rtrim($aster);
    }
    }
    if ($aster != $check){
    ?>
    <SCRIPT language="JavaScript">
    <!--hide
    function newwindow()
    {
    window.open('cust_parts_notes.php?aster=<?print ($aster);?>','Notes','width=400,height=400,resizab le=yes');
    }
    //-->
    </SCRIPT>
    <tr bgcolor=white><td align="center"><?echo "$qty";?></td><td><?echo "$partnum";?></td><td><?echo "$desc1 $desc2"?></td>
    <?
    if ($yes_no == "Y"){
    ?><td><a href="javascript:newwindow('<?print ($aster);?>')" title='<?echo "$aster"?>'>Notes</a></td><?
    } else { ?><td>&nbsp;</td><?
    }
    ?>
    </tr>
    <?
    }
    }
    odbc_close($connect);
    ?>
    </body>
    </html>

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ...sorry forgot toinclude the javascript part

    function #myjavascriptfunction#(#javascript parameter#)
    { alert('hey you pressed:'+#javascript parameter#);
    }

    as before replace everything int he # with your values

    to get information from an HTML page in a javascript function use
    document.#formname#.#ElementName#.value; /*will get a value from #ElementName# in form #formname# */

    an alterntive method is
    document.getElementById('#ElementName#').innerHTML

    HTH
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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