Click to See Complete Forum and Search --> : Replacing spaces with %20 for mailto link


blodefood
06-20-2005, 12:55 PM
I am nearly finished a web application for job postings. I would like to construct a mailto link that picks up the job title from my database. Unfortunately, there are spaces in the jobtitle and the mailto link cuts off at the first space. In my display all records page, I would like to replace the spaces with %20 but have had no success with any attempts.

The section of code I am dealing with looks like this:

Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:")
Response.Write (rsJobpost("jobtitle"))
Response.Write (">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")


Some assistance would be appreciated. Thank you.

- blodefood

buntine
06-20-2005, 10:20 PM
Have you tried:

Dim strEmail
strEmail = Replace(rsJobpost("jobtitle"), " ", "%20")

?

Although, spaces in the href of an anchor tag should not cause trouble. What is the output?

Regards.

blodefood
06-21-2005, 09:30 AM
Have you tried:

Dim strEmail
strEmail = Replace(rsJobpost("jobtitle"), " ", "%20")

?

Although, spaces in the href of an anchor tag should not cause trouble. What is the output?

Regards.

I get an error or it stops at the end of the colon after the word Application. The mailto link still works but the subject line still does not pickup the job title.

After looking at the code all day yesterday, I noticed too that there is no provision for a double quote " at the end of the ahref tag. I tried to put that in to see if it would resolve the space problem, but I kept getting either nothing or an error about mismatch.

buntine
06-21-2005, 02:09 PM
Try:

Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:" & rsJobpost("jobtitle"))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")

Regards.

blodefood
06-21-2005, 03:48 PM
Try:

Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:" & rsJobpost("jobtitle"))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")

Regards.


Thanks, I did try it and wracked my brains (as well as the brains of others on the forums) and it still didn't work. :mad: While the applyto field is used twice in the mailto link and appears correctly both times, it seems the jobtitle field lost its data the second time around on the page. :confused: I used it once further up the code. My workaround was adding a second jobtitle field called joblink. :cool: This is the field now used instead of jobtitle in the above code. I added the field to the add form as well with a javascript to copy automatically whatever is entered into the jobtitle field so the user doesn't have to retype it. I hope my HR manager is pleased!

Meantime, if I find a better way to do this, I will implement it.

- blodefood :D

mjcolli
06-21-2005, 03:51 PM
Server.UrlEncode(rsJobpost("jobtitle")))

buntine
06-21-2005, 04:18 PM
Server.UrlEncode(rsJobpost("jobtitle")))

Good point.

Can you post your full code?

Regards.

mjcolli
06-21-2005, 04:26 PM
Well, I don't have any full code, per se. That's just what I use when I need to put something in the query string. For instance:

Dim strWhatever

strWhatever = "http://www.yahoo.com?myName=" & server.urlEncode("Michael Collins")

Response.write(strWhatever)
this would write: http://www.yahoo.com?myName=Michael%20Collins

blodefood
06-21-2005, 05:08 PM
Well, I don't have any full code, per se. That's just what I use when I need to put something in the query string. For instance:

Dim strWhatever

strWhatever = "http://www.yahoo.com?myName=" & server.urlEncode("Michael Collins")

Response.write(strWhatever)
this would write: http://www.yahoo.com?myName=Michael%20Collins


I tried this too and it didn't work. I am sure it would work if I had a static URL as you have shown above.

Here's my code. I've included the entire table structure so you can see why I put the table stuff in there. If we are able to solve the problem I hope this can help someone else. If not, at least I still have my workaround.

- blodefood


<table width="660" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="2"><img src="FNHRheader650x98.jpg" width="650" height="98"></td>
</tr>
<tr bgcolor="#007A62">
<td width="258"><div align="center"><font color="#FFFFFF" size="5" face="Verdana, Arial, Helvetica, sans-serif"><strong>Job
Postings</strong></font></div></td>
<td width="382" valign="middle"><!--#include file="updateddate.inc"--> &nbsp;</td>
</tr>
<tr>
<td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Click the
blue links to open the Job Description</font></td>
</tr>
</table>

<table border="1" cellpadding="2" cellspacing="2" width="800" bgcolor="#FFFFCC">
<tr>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Job Title<br>
<font size="1"> (number of positions in brackets)&nbsp;</font>&nbsp;</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Apply To:</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Location</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;&nbsp;Date&nbsp;Posted&nbsp;&nbsp;</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;&nbsp;Date&nbsp;Closed&nbsp;&nbsp;</font></th>
</tr>
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsJobpost 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("jobpost.mdb")

'Create an ADO recordset object
Set rsJobpost = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT jobtable.* FROM jobtable;"

'Open the recordset with the SQL query
rsJobpost.Open strSQL, adoCon

'Loop through the recordset
Do While not rsJobpost.EOF

'Write the HTML to display the current record in the recordset
Response.Write ("<tr><td valign='top'>")
Response.Write("<font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write ("<a href=")
Response.Write(rsJobpost("descriptionlink"))
Response.Write(">")
Response.Write (rsJobpost("jobtitle"))
Response.Write ("</a>")
Response.Write ("&nbsp;(")
Response.Write (rsJobpost("jobtitle"))
Response.Write (rsJobpost("numberpos"))
Response.Write (")<br>Reports to:&nbsp;")
Response.Write (rsJobpost("reportto"))
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:")
Response.Write (rsJobpost("joblink"))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")
Response.Write (rsJobpost("applytotitle"))
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write (rsJobpost("joblocation"))
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write (rsJobpost("datepost"))
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write (rsJobpost("dateclose"))
Response.Write ("</font></td>")


'Move to the next record in the recordset
rsJobpost.MoveNext

Loop

'Reset server objects
rsJobpost.Close
Set rsJobpost = Nothing
Set adoCon = Nothing
%>
</table>

mjcolli
06-21-2005, 05:15 PM
it's not a dynamic link thing. It's just a string thing.
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:" & rsJobpost("jobtitle"))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")
Should be:
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:" & server.URLEncode(rsJobpost("jobtitle")))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")
You have tried this, and it didn't work?

blodefood
06-21-2005, 05:25 PM
it's not a dynamic link thing. It's just a string thing.
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:" & rsJobpost("jobtitle"))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")
Should be:
Response.Write ("</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>")
Response.Write "<a href=""mailto:"
Response.Write (rsJobpost("applyto"))
Response.Write("&subject=Application:" & server.URLEncode(rsJobpost("jobtitle")))
Response.Write (""">")
Response.Write (rsJobpost("applyto"))
Response.Write ("</a><br>")
You have tried this, and it didn't work?

Yup! And I got
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'URLEncode'
/test/jobpostings/displaywork.asp, line 86

- blodefood

buntine
06-21-2005, 06:29 PM
Hmm.. It looks fine. Can we see the output HTML of this page? Go to View > Source and paste it here.

Regards.

blodefood
06-22-2005, 09:35 AM
Hmm.. It looks fine. Can we see the output HTML of this page? Go to View > Source and paste it here.

Regards.


Here's the code. Note that the spaces in the links to job descriptions are picked up when the user copies the shortcut from another page and pastes it into the field. The other fields are typed in directly.


<html>
<head>
<title>Job Postings</title>
</head>
<body bgcolor="white" text="black" topmargin="0" leftmargin="0" rightmargin="0" marginheight="0"

marginwidth="0">
<table width="660" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="2"><img src="FNHRheader650x98.jpg" width="650" height="98"></td>
</tr>
<tr bgcolor="#007A62">
<td width="258"><div align="center"><font color="#FFFFFF" size="5" face="Verdana, Arial, Helvetica,

sans-serif"><strong>Job
Postings</strong></font></div></td>
<td width="382" valign="middle"><font face='Verdana' size='2' color='white'>Updated: Tuesday, June

21, 2005&nbsp;&nbsp;17:32&nbsp;&nbsp;ET</font> &nbsp;</td>
</tr>
<tr>
<td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Click the
blue links to open the Job Description</font></td>
</tr>
</table>

<table border="1" cellpadding="2" cellspacing="2" width="800" bgcolor="#FFFFCC">
<tr>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Job Title<br>
<font size="1"> (number of positions in brackets)&nbsp;</font>&nbsp;</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Apply To:</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Location</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica,

sans-serif">&nbsp;&nbsp;Date&nbsp;Posted&nbsp;&nbsp;</font></th>
<th><font size="2" face="Verdana, Arial, Helvetica,

sans-serif">&nbsp;&nbsp;Date&nbsp;Closed&nbsp;&nbsp;</font></th>
</tr>
<tr><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href=http://xchange/STEM/FNHR/FNCDC/Jobdescriptions/JobDescriptions/Job%20Description%20Documents/COM%20-

%20Commercial%20Mortgage%20Analyst.pdf>Commercial Mortgage Analyst - CMBS</a>&nbsp;(1)<br>Reports

to:&nbsp;Senior Manager, Commercial Administration</font></td><td valign='top'><font size='2'

face='Verdana, Arial, Helvetica, sans-serif'><a

href="mailto:rick.green@companyf.ca&subject=Application:&nbsp;Commercial Mortgage Analyst -

CMBS">rick.green@companyf.ca</a><br>Senior Manager, Commercial Mortgage Administration</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'> Melonville</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>25 April 2005</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>29 April 2005</font></td><tr><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href=http://xchange/STEM/FNHR/FNCDC/Jobdescriptions/JobDescriptions/Job%20Description%20Documents/RES%20-

%20Fulfillment%20Specialist.pdf>Fulfillment Specialist</a>&nbsp;(1)<br>Reports to:&nbsp;Team Leader,

Residential Mortgages</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica,

sans-serif'><a href="mailto:kathy.white@companyf.ca&subject=Application:&nbsp;Fulfillment

Specialist">kathy.white@companyf.ca</a><br>Manager, Residential Mortgages</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Melonville</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>15 June 2005</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Before noon on 20 June

2005</font></td><tr><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href=http://xchange/STEM/FNHR/FNCDC/Jobdescriptions/JobDescriptions/Job%20Description%20Documents/IT%20-%

20Intermediate%20Network-Desktop%20Support%20Specialist.pdf>Intermediate Network / Desktop Support

Specialist</a>&nbsp;(1)<br>Reports to:&nbsp;Director, Information Technology</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href="mailto:chris.black@companyf.ca&subject=Application:&nbsp;Intermediate Network / Desktop Support

Specialist">chris.black@companyf.ca</a><br>Director, Information Technology</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Melonville</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>15 June 2005</font></td><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>21 June 2005</font></td><tr><td

valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href=http://xchange/STEM/FNHR/FNCDC/Jobdescriptions/JobDescriptions/Job%20Description%20Documents/RES%20-

%20Internal%20Account%20Manager%20-%20Melonville.pdf>Internal Account Manager

(Melonville)</a>&nbsp;(1)<br>Reports to:&nbsp;National Director, Sales and Strategic

Relationships</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href="mailto:ben.jones@companyf.ca&subject=Application:&nbsp;Internal Account Manager

(Melonville)">ben.jones@companyf.ca</a><br>National Director, Sales and Strategic

Relationships</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica,

sans-serif'>Melonville</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica,

sans-serif'>14 June 2005</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica,

sans-serif'>20 June 2005</font></td><tr><td valign='top'><font size='2' face='Verdana, Arial, Helvetica,

sans-serif'><a

href=http://xchange/STEM/FNHR/FNCDC/Jobdescriptions/JobDescriptions/Job%20Description%20Documents/RES%20-

%20Mortgage%20Specialist%20for%20Internal%20Sales%20-%20Melonville.pdf>Mortgage Specialist for Internal

Sales - Melonville</a>&nbsp;(1)<br>Reports to:&nbsp;Manager, Internal Sales <br> (Shift

Work)</font></td><td valign='top'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'><a

href="mailto:john.smith@companyf.ca&subject=Application:&nbsp;Mortgage Specialist for Internal Sales -

Melonville">john.smith@companyf.ca</a><br>Manager, Internal Sales</font></td><td valign='top'><font

size='2' face='Verdana, Arial, Helvetica, sans-serif'>Melonville</font></td><td valign='top'><font

size='2' face='Verdana, Arial, Helvetica, sans-serif'>14 June 2005</font></td><td valign='top'><font

size='2' face='Verdana, Arial, Helvetica, sans-serif'>20 June 2005</font></td>
</table><br>
<hr width="800" align="left">
<a href="javascript:close.window()"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">close
window</font></a>
</body>
</html>

buntine
06-23-2005, 01:51 AM
The problem might lie in the fact that alot of your quotes are not closed or you have not used them at all. HTML attributes should always be enclosed in quotes.

You may also need to remove &nbsp; (which is a single space) from the records in your database.

Regards.