You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.2 KiB

{% extends 'base.html' %}
{% block content %}
<h2>Añadir nueva canción</h2>
<form method="POST">
<label for="title">Título:</label>
<input type="text" id="title" name="title" required>
<label for="author">Autor:</label>
<input type="text" id="author" name="author" required>
<label for="album_id">Álbum:</label>
<select id="album_id" name="album_id" required>
{% for album in albums %}
<option value="{{ album.id }}" data-artist="{{ album.artist }}">{{ album.name }} by {{ album.artist }}</option>
{% endfor %}
</select>
<label for="lyrics">Letra:</label>
<textarea id="lyrics" name="lyrics" required></textarea>
<button type="submit">Añadir canción</button>
</form>
<script>
function updateAuthor() {
var albumSelect = document.getElementById("album_id");
var selectedAlbum = albumSelect.options[albumSelect.selectedIndex];
var artist = selectedAlbum.getAttribute("data-artist");
document.getElementById("author").value = artist;
}
// Initialize the author field with the artist of the first album
document.addEventListener('DOMContentLoaded', function() {
updateAuthor();
});
</script>
{% endblock %}