I am trying to create a validation function for my input field, problem is I cannot capture what is in my input field!!
When I run test and put something in my input field, it returns nothing...
This is my code
<form id="myForm" name="myForm" onsubmit="test();">
<style type="text/css">
.botLayout{
padding-right:130px;
margin-right:20px;
}
</style>
<div class="botLayout">
<div name="title" align="left" style="font-size: 13px;">
<font size="4"><b>
REGISTER NOW
</b></font>
</div>
<div name="indic" align="right" style="font-size: 13px;">
<font size="1">
<font color="#ff0000">*</font>Required field
</font>
</div>
<b style="font-weight: bold;">
<div>
<div>
<div>
<b style="font-size: 13px;">First Name</b><b>
<div style="display: inline !important;">
<div style="display: inline !important;">
<span style="color: #ff0000; font-weight: normal; text-align: -webkit-right;"><font size="2">*</font></span>
</div>
</div>
</b>
</div>
<div style="font-size: 13px;">
<input type="text" maxlength="50" name="First Name" id="First Name" value="%%first name%%" size="19" />
</div>
</div>
<div>
<div>
<b style="font-size: 13px;">Last Name</b><b>
<div style="display: inline !important;">
<div style="display: inline !important;">
<span style="color: #ff0000; font-weight: normal; text-align: -webkit-right;"><font size="2">*</font></span>
</div>
</div>
</b>
</div>
<div style="font-size: 13px;">
<input type="text" maxlength="50" name="Last Name" id="Last Name" value="" size="19" />
</div>
</div>
<div>
<div>
<b style="font-size: 13px;">Email</b><b>
<div style="display: inline !important;">
<div style="display: inline !important;">
<span style="color: #ff0000; font-weight: normal; text-align: -webkit-right;"><font size="2">*</font></span>
</div>
</div>
</b>
</div>
<div style="font-size: 13px;">
<input type="text" maxlength="254" name="Email" id="Email" value="" size="19" />
</div>
</div>
<div>
<div>
<b style="font-size: 13px;">Company</b><b>
<div style="display: inline !important;">
<div style="display: inline !important;">
<span style="color: #ff0000; font-weight: normal; text-align: -webkit-right;"><font size="2">*</font></span>
</div>
</div>
</b>
</div>
<div style="font-size: 13px;">
<input type="text" maxlength="50" name="Company" id="Company" value="" size="19" />
</div>
</div>
<div>
<div>
<b style="font-size: 13px;">Job Title</b><b>
<div style="display: inline !important;">
<div style="display: inline !important;">
<span style="color: #ff0000; font-weight: normal; text-align: -webkit-right;"><font size="2">*</font></span>
</div>
</div>
</b>
</div>
<div style="font-size: 13px;">
<input type="text" maxlength="50" name="Job Title" id="Job Title" value="" size="19" />
</div>
</div>
<div style="font-size: 13px;">
<div>
<b>Contact Phone number</b>
</div>
<div>
<input type="text" maxlength="50" name="Contact Phone number" id="Contact Phone number" value="" size="19" />
</div>
</div>
<div>
<div>
<b style="font-size: 13px;">Event Location</b><b>
<div style="display: inline !important;">
<div style="display: inline !important;">
<span style="color: #ff0000; font-weight: normal; text-align: -webkit-right;"><font size="2">*</font></span>
</div>
</div>
</b>
</div>
<div style="font-size: 13px;">
<select name="Event Location" id="Event Location">
<option value="Please select" selected="selected">
Please select</option>
<option value="Adelaide">
Adelaide</option>
<option value="Canberra">
Canberra</option>
<option value="Melbourne">
Melbourne</option>
<option value="Sydney">
Sydney</option></select>
</div>
<div style="font-size: 13px;">
</div>
<div style="font-size: 13px;">
<p class="MsoNormal">
<span style="font-size: 9pt; font-family: Arial, sans-serif; color: #333333;">By providing your details above you are consenting to receive
communications from SMS Management & Technology in the future, on the
understanding that you have read and agree to our </span><a href="http://www.smsmt.com/AU/Privacy-Statement" target="_blank" title="http://www.smsmt.com/AU/Privacy-Statement" alias="http://www.smsmt.com/AU/Privacy-Statement" conversion="false"><span style="font-size: 9pt; font-family: Arial, sans-serif;">Privacy Statement</span></a><span style="font-size: 9pt; font-family: Arial, sans-serif; color: #333333;">.<o:p></o:p></span>
</p>
<p class="MsoNormal">
<span style="font-size: 9pt; font-family: Arial, sans-serif; color: #333333;">As this event is supported by Rally Software, you also consent
to receive communication from them, according to their <a href="http://www.rallydev.com/privacy-statement " title="https://www.rallydev.com/privacy-statement " alias="https://www.rallydev.com/privacy-statement " conversion="false">Privacy Statement</a>. You
will be able to opt-out of communications at any time.</span><span style="color: #1f497d;"><o:p></o:p></span>
</p>
</div>
</div>
<div style="font-size: 13px;">
<input type="submit" value="Submit" />
</div>
</div>
<span style="display: none;" id="post_code">%%[[name="FormPost";type="POST"]
VAR @de, @de_col, @updateOptions, @saveOptions, @de_statusCode, @de_statusMsg, @errorCode
SET @de = CreateObject("DataExtensionObject")
SetObjectProperty(@de, "CustomerKey", "AgileforGovRegistered")
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Email")
SetObjectProperty(@de_col, "Value", RequestParameter("Email"))
AddObjectArrayItem(@de, "Keys", @de_col)
IF NOT IsNull(RequestParameter("First Name")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "First Name")
SetObjectProperty(@de_col, "Value", RequestParameter("First Name"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Last Name")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Last Name")
SetObjectProperty(@de_col, "Value", RequestParameter("Last Name"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Email")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Email")
SetObjectProperty(@de_col, "Value", RequestParameter("Email"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Company")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Company")
SetObjectProperty(@de_col, "Value", RequestParameter("Company"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Company")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Job Title")
SetObjectProperty(@de_col, "Value", RequestParameter("Company"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Contact Phone number")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Contact Phone number")
SetObjectProperty(@de_col, "Value", RequestParameter("Contact Phone number"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Event Location")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Event Location")
SetObjectProperty(@de_col, "Value", RequestParameter("Event Location"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
SET @updateOptions = CreateObject("UpdateOptions")
SET @saveOptions = CreateObject("SaveOption")
SetObjectProperty(@saveOptions, "PropertyName", "DataExtensionObject")
SetObjectProperty(@saveOptions, "SaveAction", "UpdateAdd")
AddObjectArrayItem(@updateOptions, "SaveOptions", @saveOptions)
SET @de_statusCode = InvokeUpdate(@de, @de_statusMsg, @errorCode, @updateOptions)
IF @de_statusCode != "OK" THEN
RaiseError(@de_statusMsg, 0, @de_statusCode, @errorCode)
ENDIF
VAR @ts, @tsDef, @ts_sub, @ts_attr, @tsctr, @ts_subkey, @ts_statusCode, @ts_statusMsg, @errorCode
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey = RequestParameter("Email")
SetObjectProperty(@tsDef, "CustomerKey", "AgileForGovConfirmation")
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", RequestParameter("Email"))
IF NOT EMPTY(@ts_subkey) THEN
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
ELSE
SetObjectProperty(@ts_sub, "SubscriberKey", RequestParameter("Email"))
ENDIF
IF NOT IsNull(RequestParameter("First Name")) THEN
SET @ts_attr = CreateObject("Attribute")
SetObjectProperty(@ts_attr, "Name", "First Name")
SetObjectProperty(@ts_attr, "Value", RequestParameter("First Name"))
AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
ENDIF
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
IF @ts_statusCode != "OK" THEN
RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF
]%%</span>
<span style="display: none;" id="post_code">%%[[name="FormPost";type="POST"]
VAR @de, @de_col, @updateOptions, @saveOptions, @de_statusCode, @de_statusMsg, @errorCode
SET @de = CreateObject("DataExtensionObject")
SetObjectProperty(@de, "CustomerKey", "AgileforGovRegistered")
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Email")
SetObjectProperty(@de_col, "Value", RequestParameter("Email"))
AddObjectArrayItem(@de, "Keys", @de_col)
IF NOT IsNull(RequestParameter("First Name")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "First Name")
SetObjectProperty(@de_col, "Value", RequestParameter("First Name"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Last Name")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Last Name")
SetObjectProperty(@de_col, "Value", RequestParameter("Last Name"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Email")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Email")
SetObjectProperty(@de_col, "Value", RequestParameter("Email"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Company")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Company")
SetObjectProperty(@de_col, "Value", RequestParameter("Company"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Company")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Job Title")
SetObjectProperty(@de_col, "Value", RequestParameter("Company"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Contact Phone number")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Contact Phone number")
SetObjectProperty(@de_col, "Value", RequestParameter("Contact Phone number"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
IF NOT IsNull(RequestParameter("Event Location")) THEN
SET @de_col = CreateObject("APIProperty")
SetObjectProperty(@de_col, "Name", "Event Location")
SetObjectProperty(@de_col, "Value", RequestParameter("Event Location"))
AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF
SET @updateOptions = CreateObject("UpdateOptions")
SET @saveOptions = CreateObject("SaveOption")
SetObjectProperty(@saveOptions, "PropertyName", "DataExtensionObject")
SetObjectProperty(@saveOptions, "SaveAction", "UpdateAdd")
AddObjectArrayItem(@updateOptions, "SaveOptions", @saveOptions)
SET @de_statusCode = InvokeUpdate(@de, @de_statusMsg, @errorCode, @updateOptions)
IF @de_statusCode != "OK" THEN
RaiseError(@de_statusMsg, 0, @de_statusCode, @errorCode)
ENDIF
VAR @ts, @tsDef, @ts_sub, @ts_attr, @tsctr, @ts_subkey, @ts_statusCode, @ts_statusMsg, @errorCode
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey = RequestParameter("Email")
SetObjectProperty(@tsDef, "CustomerKey", "AgileForGovConfirmation")
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", RequestParameter("Email"))
IF NOT EMPTY(@ts_subkey) THEN
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
ELSE
SetObjectProperty(@ts_sub, "SubscriberKey", RequestParameter("Email"))
ENDIF
IF NOT IsNull(RequestParameter("First Name")) THEN
SET @ts_attr = CreateObject("Attribute")
SetObjectProperty(@ts_attr, "Name", "First Name")
SetObjectProperty(@ts_attr, "Value", RequestParameter("First Name"))
AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
ENDIF
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
IF @ts_statusCode != "OK" THEN
RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF
]%%</span><span style="display: none;" id="post_code"><!-- AMP Processing Placeholder DO NOT REMOVE --></span>
</b>
</div>
<script type="text/javascript">
var a=document.forms["myForm"]["First Name"].value;
var b=document.forms["myForm"]["Last Name"].value;
var c=document.forms["myForm"]["Email Address"].value;
var d=document.forms["myForm"]["Company"].value;
var e=document.forms["myForm"]["Job Title"].value;
function test()
{
if(1===1){
alert(a);
alert(b);
event.preventDefault();
return false;
}
}
</script>
<input type="hidden" name="__successPage" id="__successPage" value="http://pages.s7.exacttarget.com/agileforgovconfirmation/" /><input type="hidden" name="__errorPage" id="__errorPage" value="" /><input type="hidden" name="__contextName" id="__contextName" value="FormPost" /><input type="hidden" name="__executionContext" id="__executionContext" value="Post" />
Scroll to the bottom and look at the text/JS style, I've been testing for ages and I just can't figure it out!
You can't use form elements like array collection to access it's value. Because the document.forms['idOfForm']
will return form element not an array.
And for web standards you should not use space in element name and id.
Here is the working form of your code http://jsfiddle.net/vcgquvh7/