SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page refresh-adding variables breaks auto-refresh on form

    Hello all,

    I have a curious javascript problem. I have written code to autocomplete select boxes depending on the contents of the previous select box (choose country, filters cities. choose city, filters attractions in that city, etc), populated from a mysql database.

    I figured out how to refresh the page and send variables back to the page via the http GET feature in order to populate other boxes that the user had previously selected with some code:

    Code:
     
    function reloadCountry(form)
    {
      var val=form.country.options[form.country.options.selectedIndex].value; 
      var term=form.term.options[form.term.options.selectedIndex].value; 
      var provider=form.provider.options[form.provider.options.selectedIndex].value; 
      var language=form.language.options[form.language.options.selectedIndex].value;
    
    
      self.location='progSearch.php?country=' + val + '&term=' + term + '&provider=' + provider  + '&language=' + language;
    }
    This works great. However, when I add another line, very similar to the others, it suddenly breaks my page refresh functionality:


    Code:
    var prefix=form.prefix.options[form.prefix.options.selectedIndex].value;
    Any idea why this may be happening? Is there a variable limit to js that i don't know, or perhaps is prefix a reserved variable name?

    Thanks,
    Nathan

  2. #2
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no variable limit and I don't think prefix is a reservered word, but to test it, just add a 1 to it and see if anything changes.

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem solved. It turns out that the javascript halts if there is no corresponding form value that matches the javascript. I had a different name in the form vs the js. Once I corrected that, it started working.

    i wish it would give me some kind of error so I could troubleshoot this kind of thing faster...

  4. #4
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use Firefox for JS dev because it has a nice Javascript console function. The console will usually show you an error message and what line it occurred on. I like it much better than the IE debugging messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •