URL Creation.

They have: 2 posts

Joined: Dec 2004

Hi.
I have a few sites on a few different domains which share content and sometime mirror each other.

I have been trying to make a simple form where people could type the domain name into an input box, click submit and the form will add onto the end of the domain /forum, /images or another specific dirrectory.
It would save people typing the entire url and save me having to update every page for links when we move content around.

Does andbody know how i would do this?

Basically, they type domain.com in a box and the form creates the rest of the url to take them to domain.com/forum/...../......

any help would be appreciated, this has me stumped.

thanks,

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

hi, try this:

<html>
<head>
&lt;script language="javascript" type="text/javascript"&gt;
function completeUrl() {
endstr = document.getElementById('restOfUrl').value;
basicUrl = 'http://www.domain.com';

if(endstr!='') {
document.location.href = basicUrl + "/" + endstr;
}
else {
document.location.href = basicUrl;
}
}
&lt;/script&gt;

</head>

<body>
<input type="text" id="restOfUrl" value="" name="restOfUrl"/>
<input type="button" onClick="javascript:completeUrl();" value="Go"/>
</body>
</html>
'

Shakespeare: onclick || !(onclick)

They have: 2 posts

Joined: Dec 2004

Hi jack.
Thats almost what im looking for. I tried playing around with it but i couldnt get it to work.

What you posted adds the variable to the end of the domain, what i need is something that adds the domain.

---------
The red bits are what the user inputs
in yours
wwww.domain.com/forum/thread/post

what i need is
www.domain.com/forum/thread/post

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

ok, this should be it then:

<html>
<head>
&lt;script language="javascript" type="text/javascript"&gt;
function completeUrl() {
aDomain = document.getElementById('theDomain').value;
restOfUrl = 'forum/thread/post';

if(aDomain!='') {
document.location.href = aDomain + "/" + restOfUrl;
}
else {
document.location.href = aDomain;
}
}
&lt;/script&gt;

</head>

<body>
<input type="text" id="theDomain" value="" name="theDomain"/>
<input type="button" onClick="javascript:completeUrl();" value="Go"/>
</body>
</html>
'

Shakespeare: onclick || !(onclick)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.