Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink/Input Box question 1

Status
Not open for further replies.

cyberprof

Programmer
Jun 10, 2003
229
GB
Not sure if this is the right place to ask this question.

I've got a calender on a webpage, each date on the calender is a hyperlink with the date value in the link. (e.g. a href="page.asp?06/01/05">

When I click the date on the calender, how can I dynamically populate an input box on the same page.

Also, how easy will it be to lock the input box so only the date can be selected from the calender.

Cheers

J
 
for this the calendar has to be a popup...

Known is handfull, Unknown is worldfull
 
On the same page? Won't you immediately be taken away from that page when the user clicks the link?

Anyway, you could do something like this:

Code:
<script language="javascript"><!--

function fillBox(str) {
    var targ = document.forms['formname'].elements['textfieldname'];
    var dt = str.split("?");
    if (dt.length > 0) targ.value = dt[1];
}

--></script>

AND IN YOUR LINK:

<a href="page.asp?06/01/2004" onclick="fillBox(this.href);">Click Me</a>

AND YOUR TEXT BOX:

<input type="text" name="thename" onfocus="this.blur();" />

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
You have a good point regarding the link taking you to another page.

That doesn't have to happen. All I need is the date value from the calender to the input box
 
Okay, then one solution is:

Code:
<a href="#" onclick="fillBox('01/01/04'); return false;">Date Here</a>

Or you could do:

Code:
<a href="#" onclick="fillBox(this.innerHTML); return false;">Date Here</a>

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Works fine.

I've changed:

<a href="page.asp?06/01/2004" onclick="fillBox(this.href);">Click Me</a>

to

<a href="#?06/01/2004" onclick="fillBox(this.href);">06</a>

The input box fills OK, and the link remains inactive.

Thanks

J
 
Just hit a problem.

When I move back and forward to other months, I carry forward the year and month in a querystring value.

calender.asp?M=12&Y=2004

"M=12&Y=2004" is now forming part of the link in "#?"

Any ideas how to stop that happening, or is that an ASP thing.
 
what happened to "return false;" ?

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
I had to change the value in your example as the calender is dynamically created

from

onclick="fillBox('01/01/04'); return false;">

to

onclick="fillBox('<%=thisdate %>'); return false;">

but the value was lost
 
Whuh?

It should be:

Code:
<a href="#?05/03/2005" onclick="fillBox(this.href); [blue]return false;[/blue]">

But again, you don't need that unnecessary code there at all. Why not do this:

Code:
<a href="#" onclick="fillBox('<%=thisdate %>'); [blue]return false;[/blue]">

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
That is the way I strongly suggest doing it. And your function would then change slightly, to:

Code:
function fillBox(str) {
    var targ = document.forms['formname'].elements['textfieldname'];
    targ.value = str;
}

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
I've gone back to

<a href="#?<%=thisdate %>" onclick="fillBox(this.href); return false;">

and changed to

function fillBox(str) {
var targ = document.forms['formname'].elements['textfieldname'];
targ.value = str;
}

Now the whole URL is appearing in the text box

 
You are still not even pretending to listen to the advice!

With the function you have there, use this link:

Code:
<a href="#" onclick="fillBox('<%=thisdate %>'); return false;">

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Thanks, that has worked.

Sorry about this, I just got lost with all the examples, and the number of changes I had made.

I really appreciate the help

J
 
indeed, i gave a lot of examples. i shouldn't give examples that i don't suggest using, that doesn't make much sense. sorry for the confusion, glad you got it working.

:)

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top