troubleshooting Question

JQuery Challenge

Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland asked on
jQuery
12 Comments1 Solution144 ViewsLast Modified:
Hi Experts,

I'm a little rusty on JQuery and trying to update some code from a few years ago, but not getting the result i want..

I have three files -

The Form
The JQuery
The VbScript

The form allows the user to sign up for email alerts - there are 2 forms (if /else) depending on user access -

<% if ResultsCount >= 10 then %>
<% If (Request("Region") <> "") OR (Request("Sector") <> "") OR (Request("Location") <> "") OR (Request("id") <> "") then %>
<!--% If (Request("clientid") = "") AND (Request("jobtype") = "") AND (Request("hours") <> "") AND (Request("keywords") <> "") then %-->
<%if Session("UID") = ""  then %>
<form action="" name="EmailAlertsForm" id="EmailAlertsForm" class="EmailAlertsForm clearfix">
  <legend>Get <%=(MetaPage)%> emailed job alerts
  <input name="Validated" type="hidden" id="JBEValidated" value="N">
  <input type="hidden" name="Sector" id="JBESector" value="<%=Request("Sector")%>">
  <input type="hidden" name="Region" id="JBERegion" value="<%=Request("Region")%>">
  <input type="hidden" name="Location" id="JBELocation" value="<%=Request("Location")%>">
  </legend>
  <label for="email">Get the latest <%=(MetaPage)%> direct to your inbox</label>
  <div style="float: left; width: 278px; padding: 0px 4px 4px 4px; margin-top: 8px; background-color: #608EC7; border-radius: 4px;">
  <div style="float:left; width:236px; padding-top:4px;">
  <input name="email" type="email" required id="JBEemail" placeholder="Email address" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" maxlength="255"/>
  </div>
  <div style="float: left; width: 42px; padding-top: 5px;">
  <input name="EmailSignUp" type="submit" disabled="disabled" id="EmailSignUp"  value="GO"/>
  </div>
  </div>
  <!--div class="paperPlane"></div-->
  <div class="clearfix"></div>
</form>
<div id="EmailAlertsFormSuccess" style="display:none;"></div>
<%Else%>
<form action="" name="EmailAlertsForm" id="EmailAlertsFormRegistered" class="EmailAlertsForm clearfix">
  <legend>Get <%=(MetaPage)%> emailed job alerts
  <input name="Validated" type="hidden" id="JBEValidated" value="Y">
  <input type="hidden" name="Sector" id="JBESector" value="<%=Request("Sector")%>">
  <input type="hidden" name="Region" id="JBERegion" value="<%=Request("Region")%>">
  <input type="hidden" name="Location" id="JBELocation" value="<%=Request("Location")%>">
  </legend>
  <label for="email2">Get the latest <%=(MetaPage)%> direct to your inbox</label>
    <div style="float: right; width: 96px; padding: 0px 2px 4px 2px; margin-top: 8px; background-color: #608EC7; border-radius: 4px;">
    <div style="float:left; width:96px; padding-top:4px;">
    <input name="EmailSignUp2" type="submit" id="EmailSignUp2"  value="Notify Me !" disabled="disabled" style="float:right"/>
    </div>
    </div>
    
  <!--div class="paperPlane"></div-->
</form>
<div id="EmailAlertsFormSuccess" style="display:none;"></div>
<!--%End if%-->
<%End if%>
<%End if%>
<%End if%>

When the user clicks on the submit button the JQuery below should be triggered

$("#EmailAlertsForm, #EmailAlertsFormRegistered").submit(function () {
var email = $("#JBEemail").val();
var UserID = $("#JBEUserID").val();
var Validated = $("#JBEValidated").val();
var Sector = $("#JBESector").val();
var Region = $("#JBERegion").val();
var Location = $("#JBELocation").val();
var datastring = $("#EmailAlertsForm, #EmailAlertsFormRegistered").serialize();

if(email=='' || UserID=='') {
$('.error').fadeOut(200).show();
}
else {
$.ajax({
    type: "POST",
    url: "/actions/jbe.asp",
    data: dataString,
    success: function () {
$('.EmailAlertsForm').fadeOut(200).hide();
$('#EmailAlertsFormSuccess').fadeIn('slow');
if(UserID=='') {
$('#EmailAlertsFormSuccess').html('<span>' + email + '</span><br /><p>We have added ' + Sector + 'jobs ' + Region +', ' + Location +' to your alerts</p><div class="clearfix"></div>');
}
else{
$('#EmailAlertsFormSuccess').html('<span>Job Done !</span><p>We\'ll send you daily alerts about the latest ' + Sector + 'jobs in ' + Region +', ' + Location +' but before we do, please click the link on the email we have sent you to validate this email alert</p><div class="clearfix"></div>');
}
}
});
}
return false;
});

Which runs the following vbscript -

<%

Dim CMDJobsbyEmailSetup__UserID
CMDJobsbyEmailSetup__UserID = NULL
if(Session("UID") <> "") then CMDJobsbyEmailSetup__UserID = Session("UID")

Dim CMDJobsbyEmailSetup__Username
CMDJobsbyEmailSetup__Username = NULL
if(Request("Username") <> "") then CMDJobsbyEmailSetup__Username = Request("Username")

Dim CMDJobsbyEmailSetup__Region
CMDJobsbyEmailSetup__Region = NULL
if(Request("Region") <> "") then CMDJobsbyEmailSetup__Region = Request("Region")

Dim CMDJobsbyEmailSetup__Location
CMDJobsbyEmailSetup__Location = NULL
if(Request("Location") <> "") then CMDJobsbyEmailSetup__Location = Request("Location")

Dim CMDJobsbyEmailSetup__Sector
CMDJobsbyEmailSetup__Sector = NULL
if(Request("Sector") <> "") then CMDJobsbyEmailSetup__Sector = Request("Sector")

set CMDJobsbyEmailSetup = Server.CreateObject("ADODB.Command")
CMDJobsbyEmailSetup.ActiveConnection = MM_jobster_STRING
CMDJobsbyEmailSetup.CommandText = "dbo.JobsterCandidateRegisterJobsByEmail"
CMDJobsbyEmailSetup.CommandType = 4
CMDJobsbyEmailSetup.CommandTimeout = 0
CMDJobsbyEmailSetup.Prepared = true
CMDJobsbyEmailSetup.Parameters.Append CMDJobsbyEmailSetup.CreateParameter("@RETURN_VALUE", 3, 4)
CMDJobsbyEmailSetup.Parameters.Append CMDJobsbyEmailSetup.CreateParameter("@UserID", 3, 1,4,CMDJobsbyEmailSetup__UserID)
CMDJobsbyEmailSetup.Parameters.Append CMDJobsbyEmailSetup.CreateParameter("@Username", 200, 1,350,CMDJobsbyEmailSetup__Username)
CMDJobsbyEmailSetup.Parameters.Append CMDJobsbyEmailSetup.CreateParameter("@Region", 200, 1,50,CMDJobsbyEmailSetup__Region)
CMDJobsbyEmailSetup.Parameters.Append CMDJobsbyEmailSetup.CreateParameter("@Location", 200, 1,50,CMDJobsbyEmailSetup__Location)
CMDJobsbyEmailSetup.Parameters.Append CMDJobsbyEmailSetup.CreateParameter("@Sector", 200, 1,50,CMDJobsbyEmailSetup__Sector)
set JBESetup = CMDJobsbyEmailSetup.Execute
JBESetup_numRows = 0

If not JBESetup.eof then
arrsetupJBE = JBESetup.GetRows()
End if 

JBESetup.Close() 'Clean Up
Set JBESetup = Nothing 'Clean Up
Set CMDJobsbyEmailSetup = Nothing 'Clean Up

If IsArray(arrsetupJBE) Then
Dim result
if arrsetupJBE(0,0) = 1 then
result = 1
Dim objCDOSYSMail
Set objCDOSYSMail = CreateObject("CDO.Message")
Dim objCDOSYSCon
Set objCDOSYSCon = CreateObject ("CDO.Configuration")

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.net"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") ="apikey"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxxxxx"
objCDOSYSCon.Fields.Update

Set objCDOSYSMail.Configuration = objCDOSYSCon
URLShort="New Job Alert Request - testsite.co.uk"
'URLLong="http://testsite.co.uk/coms/js/unregisteredjobalert.asp?"
ReplyMail="test.user@testsite.co.uk"
ToMail="no-reply@testsite.co.uk"
FromMail="""testsite"" <job-alerts@testsite.co.uk>"
objCDOSYSMail.From = FromMail
objCDOSYSMail.To = ToMail
objCDOSYSMail.ReplyTo= ReplyMail
objCDOSYSMail.Subject = URLShort
objCDOSYSMail.TextBody = "This is a message"
objCDOSYSMail.Send
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing

Elseif arrsetupJBE(0,0) = 2 then
result = 2
Dim objCDOSYSMail2
Set objCDOSYSMail2 = CreateObject("CDO.Message")
Dim objCDOSYSCon2
Set objCDOSYSCon2 = CreateObject ("CDO.Configuration")

objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.net"
objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") ="apikey"
objCDOSYSCon2.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxxxxx"
objCDOSYSCon2.Fields.Update

Set objCDOSYSMail2.Configuration = objCDOSYSCon2
URLShort="New Job Alert Request - testsite.co.uk"
'URLLong="http://testsite.co.uk/coms/js/unregisteredjobalert.asp?"
ReplyMail="test.user@testsite.co.uk"
ToMail="no-reply@testsite.co.uk"
FromMail="""testsite"" <job-alerts@testsite.co.uk>"
objCDOSYSMail2.From = FromMail
objCDOSYSMail2.To = ToMail
objCDOSYSMail2.ReplyTo= ReplyMail
objCDOSYSMail2.Subject = URLShort
objCDOSYSMail2.TextBody = "This is a message"
objCDOSYSMail2.Send

Set objCDOSYSMail2 = Nothing
Set objCDOSYSCon2 = Nothing

Elseif arrsetupJBE(0,0) = 3 then
result = 3

Dim objCDOSYSMail3
Set objCDOSYSMail3 = CreateObject("CDO.Message")
Dim objCDOSYSCon3
Set objCDOSYSCon3 = CreateObject ("CDO.Configuration")

objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.net"
objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") ="apikey"
objCDOSYSCon3.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxxxxx"
objCDOSYSCon3.Fields.Update

Set objCDOSYSMail3.Configuration = objCDOSYSCon3
URLShort="New Job Alert Request - testsite.co.uk"
'URLLong="http://testsite.co.uk/coms/js/unregisteredjobalert.asp?"
ReplyMail="test.user@testsite.co.uk"
ToMail="no-reply@testsite.co.uk"
FromMail="""testsite"" <job-alerts@testsite.co.uk>"
objCDOSYSMail3.From = FromMail
objCDOSYSMail3.To = ToMail
objCDOSYSMail3.ReplyTo= ReplyMail
objCDOSYSMail3.Subject = URLShort
objCDOSYSMail3.TextBody = "This is a message"
objCDOSYSMail3.Send

Set objCDOSYSMail3 = Nothing
Set objCDOSYSCon3 = Nothing

End if
end if
Response.Write(result)
%>

The vbscript is working fine, when i try submitting the form the page just reloads with additional parameters in the URL, Son I'm guessing the challenge is the JQuery./...

Any ideas?

Thank you
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros