Hi! I can't seem to figure out what I'm doing wrong with this no matter how many things I try. I've looked through Google for a related issue but found nothing specific. Hopefully someone can help me.

The script runs through a external .js file calling a list of music albums, then listing the song of the album chosen via ajax. The user can then edit of delete the songs. Everything works fine until I submit the edited information through a form. When I click the submit button I get a web developer error "updateSong is not a function"

Here's the form which is loaded into the already existing page via ajax:

<?php
    include("database.php");

    $song =  $_GET['song'];

    $query = "SELECT * FROM song INNER JOIN genre ON song.gID = genre.gID INNER JOIN album ON song.alID = album.alID WHERE sID = '$song'";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)) {
    echo ("

    <form action='#' method='POST' name='updateSong' onSubmit='updateSong(\"$song\")'>
    <input name='songName' type='text' value='$row[songName]' />
    <input type='text' id='genreSearch' name='genre' alt='Genre Search' onkeyup='searchSuggest();' autocomplete='off' value='$row[genreName]'/>
    <div id='genre_search_suggest'></div>
    <input name='songURL' type='text' value='$row[songUrl]' />
    <input name='sID' type='hidden' value='$row[sID]' />
    <input name='Submit' type='Submit' value='Update Song' />
    </form>

    ");
    }

    ?>

Here's the externally called javascript that is supposed to run the edit:

function updateSong(sID) {
if(ajax) {
var song = sID;
alert("2");
ajax.open('get', './song_update.php' + encodeURIComponent(sID));
alert("3");
ajax.onreadystatechange = function() {
handleResponse(ajax);
}
ajax.send(null);
return false;

}
    }

Here's the page it's loaded into. I removed the unnecessary stuff around what this question is dealing with.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="artistPageStyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="javascripts/artistAjax.js"></script>

    </head>
    <body>

    <div id="mediaPlayerBox">

    <div id="artistAlbumList">
    <?php 
$query = "SELECT * FROM `album` INNER JOIN artist ON album.aID = artist.aID WHERE artist.LoginKey = '$token'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo ("<div id='artistAlbumBox'><div id='artistAlbum'><a href='#' onclick='loadAlbum($row[alID])'><img src='$row[albumCover]' width='75px' height='75px' border='0px' ></a></div><div id='artistAlbumLabel'>$row[albumName]</div></div>");
 }
?>
</div>

    </div>

    </body>
    </html>

Recommended Answers

All 2 Replies

BlackKite,

Try:

echo ("
<form action='#' method='POST' name='update_song' onSubmit='return updateSong(\"$song\")'>

Note, I have changed the form tag's name and added return to the onsubmit statement.

Airshow

That did the trick. Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.