Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6587967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:59:12+00:00 2026-05-25T16:59:12+00:00

I have the following javascript on my page that is supposed to generate and

  • 0

I have the following javascript on my page that is supposed to generate and go to a url instead of posting a form:

var tokenList = ["auto", "usate"];
var dirList = [];

function makeUrl(prov, manuf, model, price){
  if (_addToken(prov)){
    _joinTokens();
  }
  if (_addToken(manuf)){
    _addToken(model);
    _joinTokens();
  }
  if (price){
    return _joinDirs() + "?prezzo=" + price;
  }
  return _joinDirs();
}

function _addToken(tok){
  if (tok){
    tokenList.push(tok.replace(/ /g,"_"));
    return true;
  }
  return false;
}
function _joinTokens(){
  dirList.push(tokenList.join('-'));
  tokenList = [];
}
function _joinDirs(){
  if (tokenList){
    _joinTokens();
  }
  var url = '/' + dirList.join('/');
  if (url.charAt(url.length-1) == '/'){
    url = url.slice(0, -1);
  }
  return url;
}

It’s triggered by this code:

$(document).ready(function(){
  $('#navForm').submit(function() {
    var prov = $("[name=select-provincia]").val();
    var manuf = $("[name=select-marca]").val();
    var model = $("[name=select-modello]").val();
    var price = $("[name=select-prezzo]").val();
    var url = makeUrl(prov, manuf, model, price);
    window.location = url;
    return false;
  });
});

It’s been a long while since I translated this code from its original python. I’ve been getting rare errors in my server logs occasionally that show users trying to visit strange urls that look almost like two urls concatenated. I haven’t been able to ever duplicate such an error, but my best guess is that there is something going on with my javascript. The last two times I got this error I noticed that the user was using firefox 3.6 and iphone. Could this be some kind of browser incompatibility? Is there anything wrong with my javascript at all? Is the error just in userland?

For reference here is an example wrong url:

/auto-usate-pesaro_e_urbino/fiat-500//rimini/fiat-500?prezzo=13000

and two possible correct ones:

/auto-usate-pesaro_e_urbino/fiat-500?prezzo=13000

/auto-usate-rimini/fiat-500?prezzo=13000

Any unrelated suggestions for optimizing the code are welcome since I am bad at this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:59:13+00:00Added an answer on May 25, 2026 at 4:59 pm

    Not sure it that’s the case, but I think those strange URLs might be a result of appending the generated URL to the URL of the page being viewed. You are generating just the pathname part of the URL, not including the protocol and host name (http://foo.com) — it’s possible that some browsers are interpreting this path as relative to the current one. Try prepending the URL with the protocol and hostname.

    You might also want to see this answer: Setting JavaScript window.location and follow the advice to write the URL to window.location.href.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JavaScript in my HTML page referencing an HTML form on
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have the following Javascript code. When the page is loaded it is scrolled
I have the following javascript: $.post(/Authenticated/DeletePage/ + PageId); showStatus(Page deleted..., 10000); I would like
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
I have the following code in a jQuery JavaScript document running on a page
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
I have the following script at the end of my page: <script type=text/javascript> jQuery.noConflict();
I have a form loading on a page that loads with an onclick event
I have an html/css page that is supposed to use an html table layout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.