Anyhelp with this javascript function?

Discussion in 'JavaScript' started by xxKillswitch, Dec 20, 2007.

  1. #1
    Sorry, I don't know javascript at all. I found a tutorial from pixel2life.com for a basic ajax routine that I have been learning from. I have a function written that I think is correct...
    
    function delete_section(num){
        var xml = getXhttp( );
        if ( !xml )
    
        return false; //Usually you alert something but I don't :d
        xml.open('POST', 'index2.php?task=section&action=delete_section&secid=' +num);
        xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      
        var title = document.getElementById('news_title').value;
        var content = document.getElementById('news_content').value;
    
        //CHECKS DONE HERE.
        xml.send('news_title=' + title + '&news_content=' + content);
    
        //ANYTHING EXTRA IS ADDED HERE.
    }
    Code (markup):
    I needed to pass an arguement to it (not sure if that is right in the function too), but the function needs to be called on link click and the ajax is supposed to call a php function from another file.

    Anyways, if that function is correct, how do I call the function from a link, and is that even possible? Any help on this is greatly appreciated, or any direction.
     
    xxKillswitch, Dec 20, 2007 IP
    hogan_h likes this.
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can call that javascript function with link like this:
    
    <a href="#" onClick="delete_section(argument);return false;">Click me</a>
    
    Code (markup):
    argument should be specified of course, probably a number, you should know what it is ;)
     
    hogan_h, Dec 21, 2007 IP
    xxKillswitch likes this.