I have a music project in Perl which also requires some JavaScript but I seem to be stuck. I need to execute a program (ffplay) as a command-line application so it runs without displaying a GUI window. The Perl handles the server end of things (sqlite database access). I need JavaScript because I display track names as a button, which when clicked is supposed to run 'ffplay' to play the track named in the button code. But the button click requires JavaScript.
When I click a track name button, it only displays the first track, no matter which one I click.
The following code extracts track names from the DB.
$sth=$dbh->prepare (qq{select track from tracks where
artistid=$ArtistID and cdid=$cdID order by track});
$sth->execute();
while(@records=$sth->fetchrow_array()) {
$Track=$records[0];
print<<EndHTML;
<script>
var form=window.document.forms[0]
function process(form) {
alert ("Track: " + form.elements.Track.value)
}
</script>
EndHTML
print qq{<form name="Player">};
print qq{<input type="button" onClick="process(this.form)" name="Track" value="$Track"><br/>};
print qq{</form>};
}
$sth->finish();
SOLVED.
Changed the JavaScript function :
<html lang="en">
<head>
<script>
function process(value) {
var form =document.Player
alert ("Track: " + value)
}
</script>
</head>
<body>
<form name="Player">
<button onClick="process(this.value)" name="Track1" value="[01] Evenfall.flac">[01] Evenfall.flac</button><br/>
<button onClick="process(this.value)" name="Track2" value="[02] 6am.flac">[02] 6am.flac</button><br/>
<button onClick="process(this.value)" name="Track3" value="[03] Cut.flac">[03] Cut.flac</button><br/>
</form>
</body>
Now the alert correctly tells me which button was clicked.