0

I have this following code

jQuery('#main-menu > ul > li.search')
  .append('<ul class="search-box sub-menu"><li><form action="http://####.####.org.uk" id="searchform" method="get"><input type="text" name="s" id="s" placeholder="Search"></form></li></ul>');

It’s specifically this bit I’m interested in

<form action="http://####.####.org.uk" id="searchform" method="get">

where ####.####.org.uk is the site index of the site I’m working on, I however need this to not be hardcoded in, and just reference back to the base path, such as site.com, this code can be called from anywhere on the site, so could be called from site.com/fdsifudfa.php, site.com/test/test/123/lol.php, for example. I need this form action to go to site.com only.

I don’t want to have a fixed site path in here as this could be anything (code could move around) / be resold.

Sebastian Simon
  • 14,320
  • 6
  • 42
  • 61
Jack hardcastle
  • 2,471
  • 3
  • 17
  • 36

2 Answers2

0

How about using document.domain ?

https://developer.mozilla.org/en-US/docs/Web/API/Document/domain

gabitzish
  • 9,137
  • 6
  • 42
  • 64
0

Have you had a look at base?

<head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>

From

http://www.w3schools.com/tags/tag_base.asp

Steve Drake
  • 1,698
  • 1
  • 15
  • 35
  • depending on your situation, you *may* be opening a big can of worms when you use the `base` tag. http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag i'm avoiding it like the plague – Sharky Apr 14 '15 at 11:06
  • Interesting read, we have used it many times and its worked well. We tend to use it in angularjs sites and it works very well and its covered in googles angular docs. http://stackoverflow.com/questions/17768814/ngroute-set-base-url-for-all-routes but allways good to read the why nots :) – Steve Drake Apr 14 '15 at 11:11
  • our site can be run from `http://host` or `http://host/folder` and it helps us manage that – Steve Drake Apr 14 '15 at 11:11