?
Solved

modify this script

Posted on 2013-10-25
5
Medium Priority
?
274 Views
Last Modified: 2013-10-25
<script>



			if ("<%GetField("F_MEMTYPE")%>"== "Associé") {
				document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")
			}
			
			else if ("<%GetField("F_MEMTYPE")%>"== "Provisoire"){
				document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")
			}
			
			else if ("<%GetField("F_MEMTYPE")%>"== "Affilié"){
				document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")
			}
			
			else if ("<%GetField("F_MEMTYPE")%>"== "Adhérent"){
				document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")
			
			}
			else if ("<%GetField("F_MEMTYPE")%>"== "Enseigne"){
				document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")
			
			else{
			
			document.write ("<table border='0' cellspacing='4' cellpadding='0' width='100%'>")


			} 

</script>

Open in new window


hey,

i want to modify the above code, (in asp it would be)


if associé, or provisoire, or affilié or adhérent or enseigne then

document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")

else

document.write ("<table border='0' cellspacing='4' cellpadding='0' width='100%'>")


end if


how can i do this, modify this script? (no asp script) thx
0
Comment
Question by:fedkris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 4

Expert Comment

by:smeghammer
ID: 39599801
Hi,

Not sure what you mean - do you want a javascript equivalent structure? or do you want the ASP to write out the results of some ASP?

If javascript, use a switch/case structure:
var myvar = getRandomNumberBetweenZeroAndFive();
switch(myvar)
{
  case 0:
   //do something for zero
  break;
  case 1:
   //do something for one
  break;
  case 2:
   //do something for two
  break;
  case 3:
   //do something for three
  break;
  case 4:
   //do something for four
  break;
  case 5:
   //do something for five
  break;

  case default;
}

Open in new window


or to capture multiple cases:
var myvar = getRandomNumberBetweenZeroAndFive();
switch(myvar)
{
  case 0:
  case 1:
  case 2:
  case 3:
   //do something for zero, one, two or three
  break;
  case 4:
   //do something for four
  break;
  case 5:
   //do something for five
  break;

  case default;
}

Open in new window


For the latter, note the removal of the break statements, so that 0, 1,2 or 3 all drop through to the same handler block.

For your example, it would be:
//default output:
var htmlCode= "<table border='0' cellspacing='4' cellpadding='0' width='100%'>";
 
//either use client-side to get form field value, or a server var as you have done
var input = getFormField(); 
switch(input)
{
  case "associé":
  case "provisoire":
  case "affilié":
  case "adhérent":
  case "enseigne":
   htmlCode = "<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>"
  break;
  case default;
}

//and where you want the output:
document.write(htmlCode);  //or use DOM manipulation

Open in new window


I think switch/case is neater than multiple if/elseif statements (which you can of course do in javascript as well.)

An alternate way is to use an array and loop:
var stuffToCompare = new Array("associé","provisoire","affilié","adhérent","enseigne");
function compare(input)
{
  var output = "<table border='0' cellspacing='4' cellpadding='0' width='100%'>";
  for(var a=0;a<stuffToCompare.length;a++)
  {
    if(input == stuffToCompare[a])
    {
      //set output to alternate HTML if input matches an item in the array:
      output =  "<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>";
    }
  }
  return(output);
}

Open in new window

This is possibly a bit more involved, but will give you better control over the logic.
0
 
LVL 7

Expert Comment

by:Ironhoofs
ID: 39599804
I am not sure what you are asking (asp or not asp?). The script you allready have seems to do what you want, allthough clientside. If you want to do the check serverside and only send the appropiate <table> tag to the client, try to replace your code with this:

<%
switch (GetField("F_MEMTYPE")) {
  case "Associé":
  case "Provisoire":
  case "Affilié":
  case "Adhérent":
  case "Enseigne":
    Response.Write("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>\n");
    break;
	  
  default:
    Response.Write("<table border='0' cellspacing='4' cellpadding='0' width='100%'>\n")
    break;
}		
%>

Open in new window


N.B. the "<% %>"tags  are important because they tell the server that the content between those tags should be treated as executable ASP code.
0
 
LVL 4

Expert Comment

by:smeghammer
ID: 39599816
Not if you use Ironhoofs option, don't forget to declare you ASP language as javascript at the top of your page:
<%@ language="javascript" %>

Open in new window

0
 

Author Comment

by:fedkris
ID: 39599824
what's wrong in this script?

<script>

			if ("<%GetField("F_MEMTYPE")%>"== "Associé" or "<%GetField("F_MEMTYPE")%>"== "Provisoire" or "<%GetField("F_MEMTYPE")%>"== "Affilié" or "<%GetField("F_MEMTYPE")%>"== "Adhérent" or "<%GetField("F_MEMTYPE")%>"== "Enseigne") {
				document.write ("<table style='background-color:#C4F0B2;' border='0' cellspacing='4' cellpadding='0' width='100%'>")
			}
			
			else{
			
			document.write ("<table border='0' cellspacing='4' cellpadding='0' width='100%'>")


			} 

</script>

Open in new window

0
 
LVL 4

Accepted Solution

by:
smeghammer earned 2000 total points
ID: 39599835
replace 'or' with the javascript operator '||'.
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question