Je ne connais pas le moteur google-app, mais le javascript suivant semble faire ce que vous voulez. Le python pourrait générer les variables du tableau du côté serveur, et tout le reste fonctionnerait correctement. J'ai inclus les tableaux codés en dur afin que vous puissiez voir ce qui se passe, mais vous pouvez remplacer les tableaux avec le code python (en supposant bookpage est une sorte de dictionnaire):
i = 0
for bp in bookpage.keys():
print("mysites["+str(i)+"] = "+ bookpage[bp])+";"
print("sitenames["+str(i)+"] = "+sitenames[bp])+";"
i+=1
<html>
<body>
<script type="text/javascript">
var mysites= new Array();
mysites[0] = "http://www.google.com"; //Generate this line with python
mysites[1] = "http://www.bing.com"; //Generate this line with python
mysites[2] = "http://www.yahoo.com"; //Generate this line with python
var sitenames = new Array();
sitenames[0] = "Google"; //Generate this line with python
sitenames[1] = "Bing"; //Generate this line with python
sitenames[2] = "Yahoo"; //Generate this line with python
function changeLink(){
var index = document.getElementById("theselect").selectedIndex
document.getElementById("thelink").innerHTML=index;
var newlink = mysites[index];
var newstring = sitenames[index];
document.getElementById("thelink").href=newlink;
document.getElementById("thelink").innerHTML=sitenames[index];
}
</script>
<select id="theselect" onclick="changeLink()">
<option>Google</option>
<option>Bing</option>
<option>Yahoo</option>
</select>
<br />
<a id="thelink" href="http://www.google.com" > Google </a>
</body>
</html>
En cliquant sur la boîte d'option appelle la fonction changeLink(), qui modifie ensuite le lien et le code html interne de la balise.
Merci! Cela semble fonctionner très bien! – David