-1

I have this problem with onchange:

<form class="form" action="javascript:update();">
      <select name="calendar" id="calendar" onchange = "update(); location.href = 'http://orario-preghiera.it/newsito/try.html?id=' + this.value">
            <option value = "x" selected="selected">Bologna</option>
            <option value = "y1">Other city</option>
            <option value = "y2">Other city</option>
            <option value = "y3">Other city</option>
            <option value = "y4">Other city</option>
            <option value = "y5">Other city</option>
      </select>
</form>

When I choose a option, from x (i.e. selected) to y, the URL changes to y, and is displays the contents of y for a few seconds and then returns to x (selected), but the link changes and remains. How can I stop the content?

Thanks!

Phoenix
  • 23
  • 1
  • 1
  • 7

1 Answers1

0

Your problem is that update() function is called on every page load. Seems from the debugger that it happens from the onchange method. Anyways, I'd suggest you to change the selected attribute to the active town when the page is first requested, so that you wouldnt default to the same or remove the update from onchange on the select tag.

Also, why the hell do you have jQuery loaded twice and then you override the $ method, rendering jQuery useless.

zatatatata
  • 4,761
  • 1
  • 20
  • 41
  • @Phoenix works exactly like it did before for me. What I mean is remove the update() function from onchange attribute on the select tag. – zatatatata Jul 26 '11 at 17:21
  • @Phoenix, also you have it inside switchFormat(), which gets called on page load. Try commenting it out. – zatatatata Jul 26 '11 at 18:30
  • @Phoenix since your Javascript is garbage, you should actually set the selected attribute to the correct one on the server side (it's always on Bologna), then the update() calls wouldn't matter. Fix that and you have your solution. – zatatatata Jul 26 '11 at 18:34
  • I tried to do what you suggested me, but doesn't work. I tried to comment switchFormat(), and remove it. But nothing. You can also try, download the file here and try: http://www.2shared.com/file/qR1NowvJ/orario.html Thank you very much and thanks for your patience. ps. sorry for my bad english. – Phoenix Jul 26 '11 at 21:14
  • @Phoenix do you even have a serverside script that does something or is the javascript all there is? If so, just remove the redirect (location.href) in the onchange methods and you'll get the result. If you want bookmarkable results is javascript you have to use location.hash – zatatatata Jul 26 '11 at 21:20
  • Thank you very much. Great! You solved my problem. Now it works fine, Many Many thanks Zanfa. ;) – Phoenix Jul 26 '11 at 21:36