Prototype and window

Discussion in 'Programming' started by mustaineoz, Sep 14, 2007.

  1. #1
    I'm using prototype at my page.When i click the link,new window is opening but when i click the other link,same window is opening again.here is my code;

    <a href="#" onclick="dialog();">LINK1</a>
    <script type="text/javascript">
    function dialog() {
    Dialog.alert({url: "aaa1.html", options: {method: 'get'}},
    {className: "alphacube", width:700, okLabel: "Close"});
    }
    WindowCloseKey.init();
    </script>
    <br><a href="#" onclick="dialog();">LINK2</a></center>
    <script type="text/javascript">
    function dialog() {
    Dialog2.alert({url: "aaa2.html", options: {method: 'get'}},
    {className: "alphacube", width:700, okLabel: "Close"});
    }
    WindowCloseKey.init();
    </script>

    at both cases,aaa2.html is opening.Please help me with this!
     
    mustaineoz, Sep 14, 2007 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That would be because you've redefined your dialog function (essentially overwritten the first one with your second one).

    Normally, I would do something like:
    
    <a href="#" onclick="dialog('aaa1.html');">LINK1</a>
    <script type="text/javascript">
    function dialog(url_to_display) {
    Dialog.alert({url: url_to_display, options: {method: 'get'}},
    {className: "alphacube", width:700, okLabel: "Close"});
    }
    WindowCloseKey.init();
    </script>
    <br><a href="#" onclick="dialog('aaa2.html');">LINK2</a></center>
    
    HTML:
    or something like that...
     
    TwistMyArm, Sep 14, 2007 IP
  3. mustaineoz

    mustaineoz Active Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    twistmyarm thank you soo sooo sooo much,it is working now!!!
     
    mustaineoz, Sep 14, 2007 IP
  4. moondancer

    moondancer Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi.
    I've got a similar problem, but... just cannot cope with it.

    while ($row= mysql_fetch_array($numresults)) {
    $id= $row["id"];
    $user = $row["user"];

    echo "<a href='#' onclick='dialog();'><strong>$id</strong> - <strong>$user</strong></a>";
    echo "<script type='text/javascript'>function dialog() {
    Dialog.alert({url: 'one.php?page=$id', options: {method: 'get'}}, {className: 'alphacube', width:560, okLabel: 'Close'});
    }
    </script>";

    $count++ ;
    }


    ... the only $id I GET as a result is its latest owned value. Defiantly, overwriting functions, but ... I just cannot solve the problem. Please, help me with this!
     
    moondancer, Sep 24, 2007 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Pretty much the same answer as I gave mustaineoz... just move your dialog function out of the loop. Again this is untested code, so don't be surprised if it doesn't work exactly...

    
        echo "<script type='text/javascript'>function dialog(id_to_display) {
            Dialog.alert({url: 'one.php?page=' + id_to_display, options: {method: 'get'}}, {className: 'alphacube', width:560, okLabel: 'Close'});
    }
    </script>";
    while ($row= mysql_fetch_array($numresults)) {
        $id= $row["id"];
        $user = $row["user"];
    
        echo "<a href='#' onclick='dialog($id);'><strong>$id</strong> - <strong>$user</strong></a>";
    
        $count++ ;
    }
    
    PHP:
     
    TwistMyArm, Sep 24, 2007 IP
  6. moondancer

    moondancer Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks a lot. Really, a lot.
     
    moondancer, Sep 24, 2007 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    OK, so I'm a little confused... does it work or not?
     
    TwistMyArm, Sep 24, 2007 IP
  8. moondancer

    moondancer Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It works perfectly. Thanks again!
     
    moondancer, Sep 25, 2007 IP