Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default Javascript Function

    Hey,

    I have a JS code for loading pages via AJAX, and I want it so when a button is clicked it calls my function for saving (I need it to save multiple times, so i put it in a while() statement in PHP

    Code:
    <script type="text/javascript">
    function save()  {
    ajaxpage('savepage.php?user=<? echo $_SESSION[username]; ?>&id=<? echo $row[id]; ?>&name=<? echo $row[name]; ?>, 'savediv');
    }
    </script>
    and NOT in the while() statement I have

    Code:
    <form>
    <input type="button" name="save" onClick="javascript:save();" value="Save"></form>
    but it doesn't save, and in Firebug I get an error saying "save is not a function" when clicking the button :S, any help? Thanks

  2. #2
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Make it alert your username etc to see if thats working. 1min too..

    <script type="text/javascript">
    var username = '';
    var id = '';
    var name = '';
    function savePage()
    {
    ajaxpage('savepage.php?user=' + username + '&id=' + id + '&name=' + name, 'savediv');
    }
    </script>
    Set the vars in javascript. Call your function something else, might help.

    Let me code something up.
    Last edited by Protege; 11-05-2008 at 03:40 PM.
    Hi, names James. I am a web developer.

  3. #3
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    OK I've figured that, I made the function

    Code:
    <script language="text/javascript">
    function save () {
    <? 
    $abcd = mysql_query("SELECT * FROM texts WHERE user = '$page'");
    while($abc = mysql_fetch_array($abcd)) {
    echo("ajaxpage('save.php?id=$abc[id]', 'savediv)\n"); }
    ?>
    }
    </script>
    and in the source code i get

    Code:
    <script language="text/javascript">
    function save() {
    ajaxpage('save.php?id=1', 'savediv')
    ajaxpage('save.php?id=2', 'savediv')
    }
    </script>
    but I still get save is not a function :@

    Code:
    <form>
    <input type="button" name="save" onClick="javascript:save();" value="Save"></form>
    Last edited by Robbie; 11-05-2008 at 03:43 PM.

  4. #4
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    PHP Code:
    <?php
    $username 
    'God';
    $id '1';
    $name 'God';
    echo( 
    '<script type="text/javascript">
    var username = "' 
    $username '";
    var id = "' 
    $id '";
    var name = "' 
    $name '";
    function savePage()
    {
        alert( "Username = " + username + " ID = " + id + " Name = " + name );
        // Use that to test if the vars are set.    
        
    }
    </script>' 
    );
    ?>
    <input type="submit" value="Press" onClick="javascript:savePage();">
    Live = http://www.jamesrozee.com/robbie.php

    Its not the best way to set the vars, but thats how Id do it.

    <script type="text/javascript"> you have
    <script language="text/javascript"> <-- is deprecated.

    You know if your using AJAX to load pages, you need a backup if they don't have JAVASCRIPT enabled.
    Last edited by Protege; 11-05-2008 at 03:56 PM.
    Hi, names James. I am a web developer.

  5. #5
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    Yeah it works but I need it to save multiple things with multiple ids

  6. #6
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Give me an example of what you mean (Or what you want it to do)
    Hi, names James. I am a web developer.

  7. #7
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    Each item has an ID number and I'm tryna send the id of each one to a page with this function but as u can see above it doesnt like it

  8. #8
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Quote Originally Posted by Robbie! View Post
    Each item has an ID number and I'm tryna send the id of each one to a page with this function but as u can see above it doesnt like it
    Like this then?

    PHP Code:
    <?php
    $numbers 
    = array( 1234567891011 );
    // Im using an array as i cba to make a db.
    echo( '<script type="text/javascript">' ); // Start the javascript.
    for( $i 0$i sizeof($numbers); $i++ )
    {
        
    // you can use a while i guess.
        
    echo( 'ajaxpage("save.php?id=' $numbers$i ] . '", savediv);' );
    }
    echo( 
    '</script>' );
    ?>
    Dont worry if it isnt all on different lines, it will still work.

    LIVE = http://www.jamesrozee.com/robbie.php?id=1
    Last edited by Protege; 11-05-2008 at 05:06 PM.
    Hi, names James. I am a web developer.

  9. #9
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    Doesnt work if i put it in a function

  10. #10
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Quote Originally Posted by PureG View Post
    Like this then?

    PHP Code:
    <?php
    $numbers 
    = array( 1234567891011 );
    // Im using an array as i cba to make a db.
    echo( '<script type="text/javascript">' ); // Start the javascript.
    for( $i 0$i sizeof($numbers); $i++ )
    {
        
    // you can use a while i guess.
        
    echo( 'ajaxpage("save.php?id=' $numbers$i ] . '", savediv);' );
    }
    echo( 
    '</script>' );
    ?>
    Dont worry if it isnt all on different lines, it will still work.

    LIVE = http://www.jamesrozee.com/robbie.php?id=1
    You tried this?
    PHP Code:
    <?php
    $numbers 
    = array( 1234567891011 );
    // Im using an array as i cba to make a db.
    echo( '<script type="text/javascript">
    function sendPage()
    {' 
    ); // Start the javascript.
    for( $i 0$i sizeof($numbers); $i++ )
    {
        
    // you can use a while i guess.
        
    echo( 'ajaxpage("save.php?id=' $numbers$i ] . '", savediv);' );
    }
    echo( 
    '
    }
    </script>' 
    );
    ?>
    Hi, names James. I am a web developer.

Page 1 of 2 12 LastLast

Posting Permissions

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