javascript JumpTo in a label

javascript JumpTo in a label

Karen Carl -
回帖数:6

We just recently upgraded to Moodle 2.8.3 and our homemade jump to worked great, until we tried to edit it and resave it.  Now it has stopped working.  Here is the code we use:

<p><span style="font-size: medium;"><strong>To jump to a specific topic, select it here:</strong></span></p>

<p>

<script type="text/javascript">// </script>

</p>

<select name="subMenu" onchange="return submitForm();">

<option value="Home">Choose Topic...</option>

<option value="view.php?id=825&amp;section-0">Show All Topics</option>

<option value="view.php?id=825&amp;section=1">Aesop</option>

<option value="view.php?id=825&amp;section=2">Atlas Rubicon</option>

</select>


We have about 46 sections, but I've just included the first 3.  We have put this code in a label in the header for our course.  The dropdown part works great, it just do anything anymore when you select something.

Thanks!

回复Karen Carl

Re: javascript JumpTo in a label

Colin Fraser -
Documentation writers的头像 Testers的头像

First things first, clear the cache. Always, whenever anything goes wrong, clear the cache first. May not have any affect on a specific problem, but you are starting afresh. The next point is how are you adding the code? A drop down label in your header? Have you thought about a HTML block? Being a rather simple person, I do not like using complicated solutions, too many things can, and do, go wrong. Applying the KISS principle has worked best, for me, anyway.  


回复Colin Fraser

Re: javascript JumpTo in a label

Karen Carl -

Colin - I pasted the same code in an HTML block and it doesn't do anything.  I looked at some other courses that have the same code and haven't been edited yet since the upgrade and they are still working.  I pasted the same exact code into my label and HTML block and neither work 伤心  It seems that as soon as you edit this code in 2.8.3 it stops working.

回复Karen Carl

Re: javascript JumpTo in a label

Justin Hunt -
Particularly helpful Moodlers的头像 Plugin developers的头像

The onChange event calls the javacript function submitForm(). But I don't see that declared anywhere. 

And the script tags immediately above that are empty. 

My guess is that when you edited and saved the label, Moodle stripped out the javascript. Or you did so unwittingly. Anyway, you will have to add the submitForm function back





回复Justin Hunt

Re: javascript JumpTo in a label

Karen Carl -

Ok - I feel a little stupid...thanks for pointing out the very obvious...


I have all the code in there, but it looks like the editor is still stripping out one line:

<form name="navList" onsubmit="return submitForm();">

And that is keeping it from working.  It doesn't matter if I have it in a label or an HTML block, same result.


Here's the real code (with the submitForm() function)

<script type="text/javascript">

function submitForm() {

var list = document.navList.subMenu;

var page = list.options[ list.selectedIndex ].value;

if (page != "home")

window.location = page;

return false;

}

</script>


<form name="navList" onsubmit="return submitForm();">

<select name="subMenu" onchange="return submitForm();">

<option value="Home">Choose Topic...</option>

<option value="view.php?id=825&amp;section-0">Show All Topics</option>

<option value="view.php?id=825&amp;section=1">Aesop</option>

<option value="view.php?id=825&amp;section=2">Atlas Rubicon</option>

....more options removed for simplicity sake....


</select>

<!--<input type="submit" value="Go" />-->

</form>