[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 690
  • Last Modified:

VBScript conditional JavaScript

Is it possible for VBScript to determin what a JavaScript does, something like --

<% if Not ParentDetail.Eof then%><%if ParentDetail("Pagetype") = 2 then %>
<script>
function validatenewbulletin(formNode){
  var formValidatorInstance = new FormValidator(formNode);
  formValidatorInstance.addRule('title','Please Add a Page Title','required');
  formValidatorInstance.addRule('summary','Please Add a Page Summary','required');
  formValidatorInstance.addRule('pubdate','Please confirm the article publication date','required');
  formValidatorInstance.addRule('thumb','Please confirm the thumb image','required');
  return formValidatorInstance.validate(); 
}
</script>
<%Elseif Not ParentDetail.Eof then%><%if ParentDetail("Pagetype") = 3 then %>
<script>
function validatenewbulletin(formNode){
  var formValidatorInstance = new FormValidator(formNode);
  formValidatorInstance.addRule('title','Please Add a Page Title','required');
  formValidatorInstance.addRule('summary','Please Add a Page Summary','required');
  formValidatorInstance.addRule('pubdate','Please confirm the article publication date','required');
  formValidatorInstance.addRule('EStartDate','Please confirm the event start date','required');
  formValidatorInstance.addRule('StartDateLabel','Please confirm the event start date label','required');
  formValidatorInstance.addRule('EEndDate','Please confirm the event end date','required');
  formValidatorInstance.addRule('EndDateLabel','Please confirm the event end date label','required');
  return formValidatorInstance.validate(); 
}
</script>
<%Else%>
<script>
function validatenewbulletin(formNode){
  var formValidatorInstance = new FormValidator(formNode);
  formValidatorInstance.addRule('title','Please Add a Page Title','required');
  formValidatorInstance.addRule('summary','Please Add a Page Summary','required');
  formValidatorInstance.addRule('pubdate','Please confirm the article publication date','required');
  return formValidatorInstance.validate(); 
}
</script>
<%End if%>

Open in new window


I need my form validation javascript to validate different elements depending on the VBScript recordset values --

Thanks
0
garethtnash
Asked:
garethtnash
1 Solution
 
hieloCommented:
What you posted will work fine.  However, I find the following easier to maintain:
<script type="text/javascript">
<%
If Not ParentDetail.EOF Then
	Response.Write "var PageType=" & ParentDetail("Pagetype");
Else
	Response.Write "var PageType=0";
End if
%>

function validatenewbulletin(formNode){
	var formValidatorInstance = new FormValidator(formNode);
	formValidatorInstance.addRule('title','Please Add a Page Title','required');
	formValidatorInstance.addRule('summary','Please Add a Page Summary','required');
	formValidatorInstance.addRule('pubdate','Please confirm the article publication date','required');

	switch(PageType)
	{
		case 2:
			formValidatorInstance.addRule('thumb','Please confirm the thumb image','required');
			break;

		case 3:
			
			formValidatorInstance.addRule('EStartDate','Please confirm the event start date','required');
			formValidatorInstance.addRule('StartDateLabel','Please confirm the event start date label','required');
			formValidatorInstance.addRule('EEndDate','Please confirm the event end date','required');
			formValidatorInstance.addRule('EndDateLabel','Please confirm the event end date label','required');
			break;

	}
return formValidatorInstance.validate(); 
}
</script>

Open in new window

0
 
garethtnashAuthor Commented:
That's really neat, thank you
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now