We help IT Professionals succeed at work.
Get Started

JQuery Challenge

garethtnash
garethtnash asked
on
143 Views
Last Modified: 2017-10-30
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%>

Open in new window


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;
});

Open in new window


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)
%>

Open in new window


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
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE