By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

using a user field to create a link

P: n/a
Hi Gurus

What I would like to do is to setup a little form where people can put in a
date (e.g. Day: [....] Month..... [....] Year [......], where ... is user
input) and subsequently, will take them through to an anchor (<A
NAME={date}></A>), relating to the date that they selected. As you may have
worked out by now, I am a real novice when it comes to java script.

I have a browse using Google, but so far no luck

Let me know if you can help

Cheers
Nicolaas
Jul 23 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:oT*******************@news.xtra.co.nz...
Hi Gurus

What I would like to do is to setup a little form where people can put in a date (e.g. Day: [....] Month..... [....] Year [......], where ... is user
input) and subsequently, will take them through to an anchor (<A
NAME={date}></A>), relating to the date that they selected. As you may have worked out by now, I am a real novice when it comes to java script.

I have a browse using Google, but so far no luck

Let me know if you can help

Cheers
Nicolaas


Instead of a link, how about just going to the page?

Will this get you started? Watch for word-wrap.

<html>
<head>
<title>datelink.htm</title>
<script type="text/javascript">
function ddmmyy() {
var dd = document.getElementById("dd").value;
var mm = document.getElementById("mm").value;
var yy = document.getElementById("yy").value;
var zz = yy + mm + dd;
location.href = zz + ".htm";
}
</script>
</head>
<body>
<form>
Day: <input type="text" name="dd" size="2"> &nbsp;
Month: <input type="text" name="mm" size="2"> &nbsp;
Year:<input type="text" name="yy" size="4"> &nbsp;
<input type="button" value="OK" onclick="ddmmyy()">
</form>
</body>
</html>
Jul 23 '05 #2

P: n/a
McKirahan wrote:
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:oT*******************@news.xtra.co.nz...
Hi Gurus

What I would like to do is to setup a little form where people can put in
a
date (e.g. Day: [....] Month..... [....] Year [......], where ... is user
input) and subsequently, will take them through to an anchor (<A
NAME={date}></A>), relating to the date that they selected. As you may


have
worked out by now, I am a real novice when it comes to java script.

I have a browse using Google, but so far no luck

Let me know if you can help

Cheers
Nicolaas

Instead of a link, how about just going to the page?

Will this get you started? Watch for word-wrap.

<html>
<head>
<title>datelink.htm</title>
<script type="text/javascript">
function ddmmyy() {
var dd = document.getElementById("dd").value;


var dd=document.forms['myForm'].elements['dd'].value;
var mm = document.getElementById("mm").value;
var mm=document.forms['myForm'].elements['mm'].value;
var yy = document.getElementById("yy").value;
var yy=document.forms['myForm'].elements['yy'].value;

Picking up elements via the name attribute while using getElementByID is
an IE-ism that should be avoided. And, the forms collection is more
widely supported.
var zz = yy + mm + dd;
location.href = zz + ".htm";
document.location.href = "http://" + yy + mm + dd + ".htm";
return false;
}
</script>
</head>
<body>
<form>
<form name="myForm" action="myPage.php" onsubmit="return ddmmyy()">

Where myPage.php is a page that will return a Location Header to the
proper location, in the event JS is disabled.
Day: <input type="text" name="dd" size="2"> &nbsp;
Month: <input type="text" name="mm" size="2"> &nbsp;
Year:<input type="text" name="yy" size="4"> &nbsp;
<input type="button" value="OK" onclick="ddmmyy()">
<input type="submit" value="OK">
</form>
</body>
</html>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

P: n/a
Thanks for that guys, how do I make the php page? I have absolutely no idea
about that.
"Randy Webb" <Hi************@aol.com> wrote in message
news:8O********************@comcast.com...
McKirahan wrote:
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:oT*******************@news.xtra.co.nz...
Hi Gurus

What I would like to do is to setup a little form where people can put in

a
date (e.g. Day: [....] Month..... [....] Year [......], where ... is

userinput) and subsequently, will take them through to an anchor (<A
NAME={date}></A>), relating to the date that they selected. As you may


have
worked out by now, I am a real novice when it comes to java script.

I have a browse using Google, but so far no luck

Let me know if you can help

Cheers
Nicolaas

Instead of a link, how about just going to the page?

Will this get you started? Watch for word-wrap.

<html>
<head>
<title>datelink.htm</title>
<script type="text/javascript">
function ddmmyy() {
var dd = document.getElementById("dd").value;


var dd=document.forms['myForm'].elements['dd'].value;
var mm = document.getElementById("mm").value;


var mm=document.forms['myForm'].elements['mm'].value;
var yy = document.getElementById("yy").value;


var yy=document.forms['myForm'].elements['yy'].value;

Picking up elements via the name attribute while using getElementByID is
an IE-ism that should be avoided. And, the forms collection is more
widely supported.
var zz = yy + mm + dd;
location.href = zz + ".htm";


document.location.href = "http://" + yy + mm + dd + ".htm";
return false;
}
</script>
</head>
<body>
<form>


<form name="myForm" action="myPage.php" onsubmit="return ddmmyy()">

Where myPage.php is a page that will return a Location Header to the
proper location, in the event JS is disabled.
Day: <input type="text" name="dd" size="2"> &nbsp;
Month: <input type="text" name="mm" size="2"> &nbsp;
Year:<input type="text" name="yy" size="4"> &nbsp;
<input type="button" value="OK" onclick="ddmmyy()">


<input type="submit" value="OK">
</form>
</body>
</html>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #4

P: n/a
WindAndWaves wrote:
Thanks for that guys, how do I make the php page? I have absolutely no idea
about that.


You can start by consulting the comp.lang.javascript FAQ with regards to
top-posting and trimming your quotes. As for the PHP, it would depend on
what your server offers. It may offer PHP, ASP, PERL, nothing, or some
other language. Then, you can ask in a related newsgroup about how to
write the proper code to set a Location Header.

http://www.php.net/

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5

P: n/a
>"Randy Webb" <Hi************@aol.com> wrote in message
news:Ro********************@comcast.com...
WindAndWaves wrote:
Thanks for that guys, how do I make the php page? I have absolutely no idea about that.


You can start by consulting the comp.lang.javascript FAQ with regards to
top-posting and trimming your quotes. As for the PHP, it would depend on
what your server offers. It may offer PHP, ASP, PERL, nothing, or some
other language. Then, you can ask in a related newsgroup about how to
write the proper code to set a Location Header.

http://www.php.net/

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Thank you for that answer and I am sorry about my lack of understanding
about the News etiquette. Anyway, i have this so far:

<html>
<head>
<title>datelink.htm</title>
<script type="text/javascript">
function ddmmyy() {
var dd=document.forms['DF'].elements['dd'].value;
var dd=document.forms['DF'].elements['mm'].value;
var dd=document.forms['DF'].elements['yy'].value;
document.location.href = "#" + yy + mm + dd;
return false;

}
</script>
</head>
<body>
<form name="DF" onsubmit="return ddmmyy()">
Day: <input type="text" name="dd" size="2"> &nbsp;
Month: <input type="text" name="mm" size="2"> &nbsp;
Year:<input type="text" name="yy" size="4"> &nbsp;
<input type="submit" value="OK">
</form>
</body>
</html>
But, what happens is that I get the following in the address bar:

blah blah/go.html?dd=31&mm=10&yy=2004

While I would prefer to get go.html#31102004

How would I go about this.

TIA once more. Help is really appreciated.

Kind regards

Nicolaas
Jul 23 '05 #6

P: n/a
WindAndWaves wrote:
Anyway, i have this so far:


<html>
<head>
<title>datelink.htm</title>
<script type="text/javascript">
function ddmmyy() {
var dd=document.forms['DF'].elements['dd'].value;
var dd=document.forms['DF'].elements['mm'].value;
var dd=document.forms['DF'].elements['yy'].value;
document.location.href = "#" + yy + mm + dd;
return false;

}
</script>
</head>
<body>
<form name="DF" onsubmit="return ddmmyy()">
Day: <input type="text" name="dd" size="2"> &nbsp;
Month: <input type="text" name="mm" size="2"> &nbsp;
Year:<input type="text" name="yy" size="4"> &nbsp;
<input type="submit" value="OK">
</form>
</body>
</html>
But, what happens is that I get the following in the address bar:
blah blah/go.html?dd=31&mm=10&yy=2004
While I would prefer to get go.html#31102004

You probably copied & forgot to update the var names, I think this is
what you meant to do:

var dd=document.forms['DF'].elements['dd'].value;
var mm=document.forms['DF'].elements['mm'].value;
var yy=document.forms['DF'].elements['yy'].value;

Then build the string:

var loc='go.html'+ "#" + yy + mm + dd;
alert('loc = '+loc);
document.location.href=loc;

Mike
Jul 23 '05 #7

P: n/a
"Randy Webb" <Hi************@aol.com> wrote in message
news:8O********************@comcast.com...
document.location.href = "http://" + yy + mm + dd + ".htm";


I don't think that http://20040923.htm will display a page!

Perhaps you meant:

document.location.href = http://{domain}/{path}/ + yy + mm + dd +
".htm";

Otherwise good comments.
Jul 23 '05 #8

P: n/a
McKirahan wrote:
"Randy Webb" <Hi************@aol.com> wrote in message
news:8O********************@comcast.com...

document.location.href = "http://" + yy + mm + dd + ".htm";

I don't think that http://20040923.htm will display a page!


If I name my domain 20040923.html it might :) But you are correct.
Perhaps you meant:

document.location.href = http://{domain}/{path}/ + yy + mm + dd +
".htm";

Otherwise good comments.


Yeah, its the effects of answering in too big a hurry.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #9

P: n/a
WindAndWaves wrote:

<--snip-->
Thank you for that answer and I am sorry about my lack of understanding
about the News etiquette. Anyway, i have this so far:

<html>
<head>
<title>datelink.htm</title>
<script type="text/javascript">
function ddmmyy() {
var dd=document.forms['DF'].elements['dd'].value;
var dd=document.forms['DF'].elements['mm'].value;
var dd=document.forms['DF'].elements['yy'].value;
document.location.href = "#" + yy + mm + dd;
return false;

}
</script>
</head>
<body>
<form name="DF" onsubmit="return ddmmyy()">
Day: <input type="text" name="dd" size="2"> &nbsp;
Month: <input type="text" name="mm" size="2"> &nbsp;
Year:<input type="text" name="yy" size="4"> &nbsp;
<input type="submit" value="OK">
</form>
</body>
</html>
But, what happens is that I get the following in the address bar:

blah blah/go.html?dd=31&mm=10&yy=2004


The fact that you are even getting that URL is surprising and points to
you testing it in IE only. What it *should* be giving you is
go.html?dd=31&mm=undefined&yy=undefined. But IE is picking up the mm and
yy from the name fields, which it shouldn't. Read the other reply with
regards to your var names and how to correct the URL issue.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #10

P: n/a
"Randy Webb" <Hi************@aol.com> wrote in message
news:Xt********************@comcast.com...
McKirahan wrote:
"Randy Webb" <Hi************@aol.com> wrote in message
news:8O********************@comcast.com...

document.location.href = "http://" + yy + mm + dd + ".htm";

I don't think that http://20040923.htm will display a page!


If I name my domain 20040923.html it might :) But you are correct.
Perhaps you meant:

document.location.href = http://{domain}/{path}/ + yy + mm + dd +
".htm";

Otherwise good comments.


Yeah, its the effects of answering in too big a hurry.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Just another little thank you Randy, you were particularly helpful.
Jul 23 '05 #11

P: n/a
mscir wrote:
You probably copied & forgot to update the var names, I think this is
what you meant to do:

var dd=document.forms['DF'].elements['dd'].value;
var mm=document.forms['DF'].elements['mm'].value;
var yy=document.forms['DF'].elements['yy'].value;

Then build the string:

var loc='go.html'+ "#" + yy + mm + dd;
alert('loc = '+loc);
document.location.href=loc;


He would be better off with

var e = document.forms['DF'].elements;
var dd = e['dd'].value;
var mm = e['mm'].value;
var yy = e['yy'].value;
...
var loc = 'go.html' + "#" + yy + mm + dd;
alert('loc = ' + loc);
location.href = loc;
PointedEars
--
"Where "Life" is a four letter word"
-- sy****@freds.cojones.com
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.