PDA

View Full Version : Show variable as a link in form output?



pgheagle
07-31-2012, 03:19 AM
I admit I an a newb when it comes to alot of things.

I have a countdown timer script that I am using for an Alumni website that allows me to show a countdown timer. The output variable of the timer shows based on 3 options, Shows a countdown timer if the time is in the future. It shows a message if the timer is set for the day of the event, and another message if the timer has past the date.

Is there a way so that the output message is a link to a page.

Example: As the script is showing below the timer is set so the event has past. So in the form box it shows "Class of 1965 - There is no reunion information available". Is there a way I can embed the above text with a link that would take you to another page? And is there a way to have the countdown timer have an embeded link as well. What I am trying to do is set it so that no matter what is showing in the form output field has an embedded link to a page for more information.

<form name="count">
<input type="text" size="67" name="count2" style="border:3px double #000000; font-family: Bell MT; font-size: 14pt; color: #000000; font-style:oblique; text-align:center">
</form>

<font color="#FFFF00"><span style="font-size: 1pt">

<script>
//Class of 1965
//change the text below to reflect your own,
var before="the class of 1965 reunion!"
var current="Today is the day of the Class of 1965 Reunion!"
var none="Class of 1965 - There is no reunion information available."
var past="Class of 1965 - There is no reunion information available."
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.forms.count.count2.value=current
return
}
if(yr==0&&m==0&&d==0){
document.forms.count.count2.value=none
return
}
if(dday<0){
document.forms.count.count2.value=past
return
}

else
document.forms.count.count2.value="Only "+dday+ " days until "+before+ " "+m+ "/"+d+ "/"+yr
setTimeout("countdown(theyear,themonth,theday)",1000)
}
//enter the count down date using the format year/month/day
countdown(2012,6,10)
</script>
</span></font>

bernie1227
07-31-2012, 06:55 AM
Can't you just put <a> tags around the different outputs?

keyboard
07-31-2012, 08:22 AM
Please use the forum's bbcode tags to make it more readable:

for php code............
<?php /* code goes here */ ?>
for html...............
<!-- markup goes here -->.....
for js/css/other.......
code goes here................

pgheagle
07-31-2012, 01:23 PM
I have tried what I thought with the <a>.

var past=<a href = "reunion-1965.php" <b>Class of 1965 - There is no reunion information available.</b></a>

But when I do that, the form output field shows nothing in it.

bernie1227
08-01-2012, 08:39 AM
Is it because you didn't actually end the start of the a tag? Try this:


var past=<a href="reunion-1965.php"> <b>Class of 1965 - There is no reunion information available.</b></a>

pgheagle
08-01-2012, 08:39 PM
Once you mentioned it, I realized that may be the problem. I even found one other open tag. (Stupid mistakes LOL!) But that didn't correct what I am trying to do.

Here is the full script as I am trying to use it. You will notice there are two var=past lines (One commented out. I highlighted both lines.)
If I use the one without the link it shows up and looks right.
If I use the one WITH the link I get nothing in the form field at all.. :confused:


<form name="count">
<input type="text" size="67" name="count2" style="border:3px double #000000; font-family: Bell MT; font-size: 14pt; color: #000000; font-style:oblique; text-align:center">
</input>
</form>

<font color="#FFFF00"><span style="font-size: 1pt">

<script>
//Class of 1965
//change the text below to reflect your own,
var before="the class of 1965 reunion!"
var current="Today is the day of the Class of 1965 Reunion!"
var none="Class of 1965 - There is no reunion information available."
var past="Class of 1965 - There is no reunion information available."
// var past=<a href = "reunion-1965.php"> <b>Class of 1965 - There is no reunion information available.</b></a>
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.forms.count.count2.value=current
return
}
if(yr==0&&m==0&&d==0){
document.forms.count.count2.value=none
return
}
if(dday<0){
document.forms.count.count2.value=past
return
}

else
document.forms.count.count2.value="Only "+dday+ " days until "+before+ " "+m+ "/"+d+ "/"+yr
setTimeout("countdown(theyear,themonth,theday)",1000)
}
//enter the count down date using the format year/month/day
countdown(2012,6,10)
</script>
</span></font>

bernie1227
08-01-2012, 08:56 PM
Lookalike the problem is no quotation marks, try:


var past="<a href = "reunion-1965.php"> <b>Class of 1965 - There is no reunion information available.</b></a>"

pgheagle
08-01-2012, 09:26 PM
I tried that also.

I tried placing the "'s at the begining and the end. And what I got was
<a href = reunion-1965.php> <b>Class of 1965 - There is no reunion information available.</b></a> showing in the field box.

I also tried placing the "'s like this "Class of 1965 - There is no reunion information available." in the line and then I got nothing again.


Am I to assume that you can not have a link inside of a form box??

Assuming that anything placed inside the quotes of the variable is output as it is and not run as code.

bernie1227
08-01-2012, 09:49 PM
I think I get it now, the problem is that the code isn't actually being written to a place where the HTML tags can function correctly, so only text will work.

pgheagle
08-01-2012, 10:08 PM
Yes Bernie.

I now assumke that I was right that since the information is being inserted into a form box that the HTML code will not work.

I thought I had seen this done somewhere before where it worked. I searched but can't find where or how it was done :(

keyboard
08-04-2012, 01:35 AM
var past="<a href = "reunion-1965.php"> <b>Class of 1965 - There is no reunion information available.</b></a>"

This code will never work because of the "" in the href tag... it thinks it's ending the variable past even though it shouldn't be...

Try this instead


var past="<a href = 'reunion-1965.php'> <b>Class of 1965 - There is no reunion information available.</b></a>"ead

bernie1227
08-04-2012, 01:55 AM
or you could escape them:


var past="<a href = \"reunion-1965.php\"> <b>Class of 1965 - There is no reunion information available.</b></a>"

pgheagle
08-04-2012, 01:57 AM
Thanks for the extra eyes. I agree that the extra "'s would kill off the VAR statement.
I did change it and use the' instead but with the same results. It just shows the whole variable in the output.
You can see what it is looking like at:
http://kohs.us/1965.htm

The whole point of trying to get this to show as a link as I wanted to use this as an include in other pages and the link would take you to the page with information.

bernie1227
08-04-2012, 02:06 AM
here's a novel idea, you could set up an a tag in the code and then output the correect text and change the href depending on what day it is.