Dynamic creation of URL

P

paul544

I need a script that will allow a user to enter variables into a form
and then have a script generate a URL based on the input and then go
there.

I have an intranet. The address format is the same, but there are 2
variables in the address that change. Normally the entire address
must be typed in order to change what you want. I'd like to make it
easier by just parsing input from two fields and put them in an
address.

Any help is appreciated.
 
L

Laurent Bugnion, GalaSoft

Hi,
I need a script that will allow a user to enter variables into a form
and then have a script generate a URL based on the input and then go
there.

I have an intranet. The address format is the same, but there are 2
variables in the address that change. Normally the entire address
must be typed in order to change what you want. I'd like to make it
easier by just parsing input from two fields and put them in an
address.

Any help is appreciated.

I must assume a few things, because your post is not complete enough.

<FORM NAME="frmValues" ID="frmValues">
<INPUT TYPE="text" NAME="tfValue1" ID="tfValue1">
<BR>
<INPUT TYPE="text" NAME="tfValue2" ID="tfValue2">
</FORM>

JavaScript:

var strValue1 = document.frmValues.tfValue1.value;
var strValue2 = document.frmValues.tfValue2.value;

var strUrl = "http://www.helloworld.com/" + strValue1
+ "/" + strValue2;

top.location = strUrl;

HTH,

Laurent
 
P

paul544

Laurent Bugnion said:
Hi,


I must assume a few things, because your post is not complete enough.

<FORM NAME="frmValues" ID="frmValues">
<INPUT TYPE="text" NAME="tfValue1" ID="tfValue1">
<BR>
<INPUT TYPE="text" NAME="tfValue2" ID="tfValue2">
</FORM>

JavaScript:

var strValue1 = document.frmValues.tfValue1.value;
var strValue2 = document.frmValues.tfValue2.value;

var strUrl = "http://www.helloworld.com/" + strValue1
+ "/" + strValue2;

top.location = strUrl;

HTH,

Laurent

Thanks! Considering how little info I gave, you nailed it. Thanks a bunch.
 
P

paul544

Laurent Bugnion said:
Hi,


I must assume a few things, because your post is not complete enough.

<FORM NAME="frmValues" ID="frmValues">
<INPUT TYPE="text" NAME="tfValue1" ID="tfValue1">
<BR>
<INPUT TYPE="text" NAME="tfValue2" ID="tfValue2">
</FORM>

JavaScript:

var strValue1 = document.frmValues.tfValue1.value;
var strValue2 = document.frmValues.tfValue2.value;

var strUrl = "http://www.helloworld.com/" + strValue1
+ "/" + strValue2;

top.location = strUrl;

HTH,

Laurent

Oh, BTW, is there anyway to make the resulting URL launch in a new window?
Thanks again.
 
L

Laurent Bugnion, GalaSoft

Hi,
Oh, BTW, is there anyway to make the resulting URL launch in a new window?
Thanks again.

That would be something like:

var g_wPopUp = null;

function openPopUp()
{
var strValue1 = document.frmValues.tfValue1.value;
var strValue2 = document.frmValues.tfValue2.value;

var strUrl = "http://www.helloworld.com/" + strValue1
+ "/" + strValue2;

if ( ( g_wPopUp == null )
|| g_wPopUp.closed )
{
var iWidth = WWW;
var iHeight = HHH;
var iLocX = ( screen.width - iWidth ) / 2;
var iLocY = ( screen.height - iHeight ) / 2;
var strFeatures = "width=" + iWidth
+ ",height=" + iHeight
+ ",screenX=" + iLocX
+ ",screenY=" + iLocY
+ ",left=" + iLocX
+ ",top=" + iLocY;

g_wPopUp = open( strUrl, NAME, strFeatures );
}
else
{
g_wPopUp.location = strUrl;
g_wPopUp.focus();
}
}

Don't forget to replace WWW with the desired pop-up width, HHH with its
height and NAME with a unique name.

The function openPopUp could be called ONCLICk of a button in your form,
for example.

It's also nice to close the pop-up when the user leaves the page. This
is done with (in the main window):

<BODY ONUNLOAD="unloadMe();">

and

function unloadMe()
{
if ( ( g_wPopUp != null )
&& !g_wPopUp.closed )
{
g_wPopUp.close();
}
g_wPopUp = null;
}

HTH,

Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top