Grant Palin
06-09-2004, 10:17 PM
In my ASP page, I want to output some buttons depending on the current page. I can create them through ASP fine, and originally just dropped them on the page. However, since the buttons use javascript in their onclick event, the buttons are useless in non-javascript browsers.
I then went on to create text-link versions of the buttons, using <a href=...> instead of buttons. I then output those links through ASP, inside a noscript tag. My idea was to output the buttons using javascript, and if that didn't work, then the plain text links would be visible and usable instead.
The plain text links appear and are usable when I disable javascript in my browser. However, when I re-enable javascript, the buttons do not appear, and neither do the text links (which is to be expected).
So, I have the following ASP code that creates strings holding the HTML to create the buttons and the links:
'Add First and Previous buttons'
objButtonString.Add(" <input type=""button"" value=""First"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=1';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=1"">First</a> |" & vbCrLf)
objButtonString.Add(" <input type=""button"" value=""Previous"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=" & intCurPage - 1 & "';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=" & intCurPage - 1 & """>Previous</a> |" & vbCrLf)
'Add Next and Last buttons'
objButtonString.Add(" <input type=""button"" value=""Next"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=" & intCurPage + 1 & "';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=" & intCurpage + 1 & """>Next</a> |" & vbCrLf)
objButtonString.Add(" <input type=""button"" value=""Last"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=" & intPageCount & "';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=" & intPageCount & """>Last</a> |" & vbCrLf)
And the following code outputs those string:
objNavString.Add(" <script type=""type/javascript"">" & vbCrLf)
objNavString.Add(" <!--" & vbCrLf)
objNavString.Add(" document.write('" & objButtonString.Value & "')" & vbCrLf)
objNavString.Add(" -->" & vbCrLf)
objNavString.Add(" </script>" & vbCrLf)
objNavString.Add(" <noscript>" & vbCrLf)
objNavString.Add(objLinkString.Value)
objNavString.Add(" </noscript>" & vbCrLf)
All well and good. I load the page, no errors...and no buttons (and yes, javascript is enabled).
Here's the HTML I got from viewing the source:
<script type="type/javascript">
<!--
document.write(' <input type="button" value="First" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1';" /> <input type="button" value="Previous" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1';" /> <input type="button" value="Next" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=3';" /> <input type="button" value="Last" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=4';" />')
-->
</script>
<noscript>
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1">First</a> |
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1">Previous</a> |
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=3">Next</a> |
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=4">Last</a> |
</noscript>
Now, I'm thinking it's got something to do with the quotes in the resulting HTML when doing document.write in javascript...am I right? I'm not too familiar with javascript, so I turn to those who are to point out the (quite likely simple) error.
I then went on to create text-link versions of the buttons, using <a href=...> instead of buttons. I then output those links through ASP, inside a noscript tag. My idea was to output the buttons using javascript, and if that didn't work, then the plain text links would be visible and usable instead.
The plain text links appear and are usable when I disable javascript in my browser. However, when I re-enable javascript, the buttons do not appear, and neither do the text links (which is to be expected).
So, I have the following ASP code that creates strings holding the HTML to create the buttons and the links:
'Add First and Previous buttons'
objButtonString.Add(" <input type=""button"" value=""First"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=1';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=1"">First</a> |" & vbCrLf)
objButtonString.Add(" <input type=""button"" value=""Previous"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=" & intCurPage - 1 & "';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=" & intCurPage - 1 & """>Previous</a> |" & vbCrLf)
'Add Next and Last buttons'
objButtonString.Add(" <input type=""button"" value=""Next"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=" & intCurPage + 1 & "';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=" & intCurpage + 1 & """>Next</a> |" & vbCrLf)
objButtonString.Add(" <input type=""button"" value=""Last"" onclick=""document.location.href=" & _
"'results.asp?" & objQueryString.Value & "¤tpage=" & intPageCount & "';"" />")
objLinkString.Add(" | <a href=""results.asp?" & objQueryString.Value & "¤tpage=" & intPageCount & """>Last</a> |" & vbCrLf)
And the following code outputs those string:
objNavString.Add(" <script type=""type/javascript"">" & vbCrLf)
objNavString.Add(" <!--" & vbCrLf)
objNavString.Add(" document.write('" & objButtonString.Value & "')" & vbCrLf)
objNavString.Add(" -->" & vbCrLf)
objNavString.Add(" </script>" & vbCrLf)
objNavString.Add(" <noscript>" & vbCrLf)
objNavString.Add(objLinkString.Value)
objNavString.Add(" </noscript>" & vbCrLf)
All well and good. I load the page, no errors...and no buttons (and yes, javascript is enabled).
Here's the HTML I got from viewing the source:
<script type="type/javascript">
<!--
document.write(' <input type="button" value="First" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1';" /> <input type="button" value="Previous" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1';" /> <input type="button" value="Next" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=3';" /> <input type="button" value="Last" onclick="document.location.href='results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=4';" />')
-->
</script>
<noscript>
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1">First</a> |
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=1">Previous</a> |
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=3">Next</a> |
| <a href="results.asp?type=LHA&subtype=®ion=1®ion=2®ion=3®ion=4®ion=5&year=1976&year=1981&year=1986&year=1987&year=1988&year=1989&agegroup=totals&gender=a&output=browser&rowsperpage=25¤tpage=4">Last</a> |
</noscript>
Now, I'm thinking it's got something to do with the quotes in the resulting HTML when doing document.write in javascript...am I right? I'm not too familiar with javascript, so I turn to those who are to point out the (quite likely simple) error.