I'm writing a code where there is a string to be compared with the variable array. Here if it is found, I need to alert that the match is found. Below is my code.
Here I'm comparing a single string with the array of strings. I'm not comparing two different js arrays.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script type="text/javascript">
function addTable() {
var dataTerm = document.getElementById('Select2').value;
var cancellations = new Array();
var changeInfo = new Array();
var idq = new Array();
var others = new Array();
var replace = new Array();
var moreInfo = new Array();
var salesRep = new Array();
var custReq = new Array();
var myTableDiv = document.getElementById("myDynamicTable");
myTableDiv.border = "1";
var variablesArray = new Array[cancellations, changeInfo, idq, others, replace, moreInfo, salesRep, custReq];
for (var i = 0; i < variablesArray.length; i++) {
if (dataTerm == variablesArray[i].value) {
alert("matched at" + variablesArray[i].value);
}
}
}
</script>
</head>
<body>
<table class="auto-style1">
<tr>
<td class="auto-style3">Renewal/Product #</td>
<td class="auto-style4">
<input id="Text1" type="text" /></td>
<td class="auto-style5">Product Title</td>
<td>
<input id="Text2" type="text" /></td>
</tr>
<tr>
<td class="auto-style3">Account #</td>
<td class="auto-style4">
<input id="Text3" type="text" /></td>
<td class="auto-style5">Product Code</td>
<td>
<input id="Text4" type="text" /></td>
</tr>
<tr>
<td class="auto-style3">Invoice #</td>
<td class="auto-style4">
<input id="Text5" type="text" /></td>
<td class="auto-style5">Suspended Date</td>
<td>
<input id="Text6" type="text" /></td>
</tr>
<tr>
<td class="auto-style3">Shipment / To #</td>
<td class="auto-style4">
<input id="Text7" type="text" /></td>
<td class="auto-style5">Term Inc/ Dec</td>
<td>
<input id="Text8" type="text" /></td>
</tr>
<tr>
<td class="auto-style3">Tracking #</td>
<td class="auto-style4">
<input id="Text9" type="text" /></td>
<td class="auto-style5">Qty Inc/ Dec From</td>
<td>
<input id="Text10" type="text" /></td>
</tr>
<tr>
<td class="auto-style3">Unit #</td>
<td class="auto-style4">
<input id="Text11" type="text" /></td>
<td class="auto-style5">Qty Inc/ Dec To</td>
<td>
<input id="Text12" type="text" /></td>
</tr>
<tr>
<td class="auto-style3">Billing Address</td>
<td class="auto-style4">
<input id="Text13" type="text" /></td>
<td class="auto-style5">E-mail ID</td>
<td> </td>
</tr>
<tr>
<td class="auto-style3">Name</td>
<td class="auto-style4">
<input id="Text14" type="text" /></td>
<td class="auto-style5">Request Type</td>
<td>
<select id="Select2" name="D2">
<option value="" disabled selected>Select your option</option>
<option value="Cancellations">Cancellations</option>
<option value="Changing Information">Changing Information</option>
<option value="Increase or Decrease Quantity/Term/Users">Increase or Decrease Quantity/Term/Users</option>
<option value="Others">Others</option>
<option value="Replacement">Replacement</option>
<option value="Fore more information">Fore more information</option>
<option value="Contacting Sales rep">Contacting Sales rep</option>
<option value="Requesting Customer">Requesting Customer</option>
</select>
</td>
</tr>
<tr>
<td class="auto-style3" colspan="4">
<input id="Button1" type="button" value="Click Me" onclick="addTable()" /></td>
<td class="auto-style4" colspan="4"> </td>
<td class="auto-style5" colspan="4"> </td>
<td colspan="4"> </td>
</tr>
</table>
<br />
<br />
<br />
<br />
<div style="height: 420px" id="myDynamicTable">
</div>
</body>
</html>
Here in my case, to my surprise nothing happens when I click on the button.