ankouny
asked on
Javascript function is not fired ?
Hello,
I'm trying to call a javascript function in my code and it seems not to be running. below is my code :
<a href="#" onclick="UpdateContacts(); "><img border="0" src="../images/Buttons/nex t.png" /></a>
and dunction UpdateContacts() is in the <script type="text/javascript"> tag.
Please help me what could be the problem.
Knowing that I tried to make the body run under server and also did not work.
I'm trying to call a javascript function in my code and it seems not to be running. below is my code :
<a href="#" onclick="UpdateContacts();
and dunction UpdateContacts() is in the <script type="text/javascript"> tag.
Please help me what could be the problem.
Knowing that I tried to make the body run under server and also did not work.
you may have an error inside UpdateContacts()
ASKER
the alert worked but the functions did not work ? any suggestion on how to debug it ?
Hi ankouny,
There's no problem with the script you posted. The problem must be in your UpdateContacts() function. Can you post the UpdateContacts() function so that we can also check it?
There's no problem with the script you posted. The problem must be in your UpdateContacts() function. Can you post the UpdateContacts() function so that we can also check it?
check line 13 :)
ASKER
What do you mean by line 13 ? I did not get it :)
a stupid joke... sorry... Mr_Wizzy is right, post your code if you want we debug it with you
ASKER
The button is at the very bottom .
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="IUW_Step2.aspx.vb" Inherits="SalesNexus.IUW_Step2" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head runat="server">
<title>IUW_Step2</title>
<link type="text/css" href="../styles/Controls.css" rel="Stylesheet" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script type="text/javascript">
function formDuplicated(idx) {
var obj = document.getElementById('mapfield' + idx);
var val = obj.value
var f = document.forms[0]
for (var i = 0; i < f.elements.length; i++) {
var e = f.elements[i]
if (e.type == "select-one") {
if ((e.name != obj.name) && (e.value != "0") && (e.value == val)) {
e.value = "0";
return;
}
}
}
if (val != "0") {
document.getElementById("match" + idx).disabled = false;
document.getElementById("update" + idx).disabled = false;
}
else {
document.getElementById("match" + idx).checked = false;
document.getElementById("update" + idx).checked = false;
document.getElementById("match" + idx).disabled = true;
document.getElementById("update" + idx).disabled = true;
}
}
function ChangeUpdateCheckboxValue(index) {
var dropdown = document.getElementById('mapfield' + index);
var chkbox = document.getElementById('update' + index);
var oppbox = document.getElementById('match' + index);
chkbox.value = dropdown.value;
oppbox.checked = false;
}
function ChangeMatchCheckboxValue(index) {
var dropdown = document.getElementById('mapfield' + index);
var chkbox = document.getElementById('match' + index);
var oppbox = document.getElementById('update' + index);
chkbox.value = dropdown.value;
oppbox.checked = false;
}
function UpdateContacts() {
alert('Update Contacts');
var mode = document.forms[0].mode.value;
alert(mode );
var count = 0;
var isValid = false;
if (mode == "update") {
alert('mode == update');
var els = document.getElementsByTagName("input");
for (var i = 0; i < els.length; i++) {
if ((els[i].type == "checkbox") && (els[i].name == "match" + count)) {
count++;
if (els[i].checked) {
isValid = true;
break;
}
}
}
}
else {
alert('else');
var els = document.getElementsByTagName("select");
alert(els);
for (var i = 0; i < els.length; i++) {
alert('for loop');
if (els[i].name != "userlist")
count++;
}
if (count == document.forms[0].count.value)
isValid = true;
}
alert('is Valid Fn');
if (isValid) {
if (document.getElementById("SaveMappingForNextImport").checked) {
document.forms[0].SaveMapping.value = "Save";
if (document.getElementById("importMode").checked) {
document.forms[0].ImportUpdateFlag.value = "Import";
} else {
document.forms[0].ImportUpdateFlag.value = "Update";
}
//document.forms[0].submit();
}
//else {
document.forms[0].action = "IUW_Step3.aspx";
document.forms[0].submit();
//}
}
else {
if (mode == "update")
alert("You must select at least one column to match records for updating.");
}
}
function changeMode() {
var importMode = document.getElementById("importMode");
var importNew = document.getElementById("importNonmatches1");
if (importMode.checked) {
document.forms[0].mode.value = "import";
document.getElementById("importNonmatches0").disabled = true;
document.getElementById("importNonmatches1").disabled = true;
document.getElementById("matchDuplicate").innerHTML = "Select for Duplicate-check";
var els = document.getElementsByName("updateGrp")
for (var i = 0; i < els.length; i++)
els[i].style.visibility = "hidden";
}
else {
document.forms[0].mode.value = "update";
var updateOption = document.getElementById("importNonmatches0");
if (updateOption.checked)
document.forms[0].importNonmatches.value = "no";
else
document.forms[0].importNonmatches.value = "yes";
document.getElementById("importNonmatches0").disabled = false;
document.getElementById("importNonmatches1").disabled = false;
document.getElementById("matchDuplicate").innerHTML = "<b>Select For Matching<b>";
var els = document.getElementsByName("updateGrp");
for (var i = 0; i < els.length; i++) {
els[i].style.visibility = "visible";
}
}
if (importMode.checked || importNew.checked)
document.getElementById("userlist").disabled = false;
else
document.getElementById("userlist").disabled = true;
}
</script>
</head>
<body>
<form id="form2" >
<input type="hidden" name="mode" value="import" />
<input type="hidden" name="importNonmatches" value="no" />
<input type="hidden" name="SaveMapping" value="" />
<input type="hidden" name="ImportUpdateFlag" />
<input type="hidden" name="recordMgrId" />
<table style="border: 2px; border-color: #6a6a6a; border-style: solid; display: block; width: 636px; margin-left: 10px;">
<tr>
<td class="fontOnly">
<h2 class="fontOnly">
Import/Update Wizard: Step 2</h2>
Select the mode you wish to use:<br />
<input type="radio" name="importRadio" id="importMode" value="import" checked onclick="changeMode();">
Import as new contacts<br />
<input type="radio" name="importRadio" id="updateMode" value="update" onclick="changeMode();">
Update existing contacts by the matching the specified column(s).<br>
<input type="radio" value="no" name="updateOption"
id="importNonmatches0" disabled onclick="changeMode();" checked>
Do not import non-matching records as new contacts<br>
<input type="radio" value="yes" name="updateOption"
id="importNonmatches1" disabled onclick="changeMode();">
Import non-matching records as new contacts<br>
<br />
Select the record manager to assign to contacts being imported:
<select class="fontOnly" name="userlist" id="userlist">
<%= optionStr %>
</select><br />
<br />
Please map each field below and select the field(s) you wish to use for matching
records.<br />
<br />
<input type="radio" name="SaveFieldMappingRadio" id="SaveMappingForNextImport" value="SaveFieldMapping"
onclick="" />
Save This Field Mapping For My Next Import.<br />
<br />
<% Dim headers As String() = Session("IUW_Headers")%>
<input type="hidden" name="count" value="10" />
<table cellspacing="0" cellpadding="4">
<tr bgcolor="#c0c0c0">
<td nowrap>
<span class="fontOnly"><b>CSV Header</b></span>
</td>
<td nowrap>
<span class="fontOnly"><b>Contact Field</b></span>
</td>
<td nowrap align="center">
<span class="fontOnly" id="matchDuplicate"><b>Select for Duplicate-check</b></span>
</td>
<td nowrap align="center">
<span id="updateGrp" style="visibility: hidden; font-family: Tahoma; font-size: 11px;
color: #6a6a6a;" name="updateGrp"><b>Select for Updating</b></span>
</td>
</tr>
<%
'''''''''Aloha Technology 07-Oct-2010
Dim storedHeaders, storedMapToFields, storedMatch, storedUpdate As String()
Dim headerId As Integer
If dt.Rows.Count > 0 Then
storedHeaders = strSourceField.Split("|")
storedMapToFields = strMaptoFieldId.Split("|")
storedMatch = strMatchField.Split("|")
storedUpdate = strUpdateField.Split("|")
'Session("FieldIds") = storedMapToFields
End If
For i As Integer = 0 To UBound(headers) - 1
%>
<tr>
<td class="fontOnly" width="125">
<%=headers(i)%>
</td>
<td width="250">
<%
If dt.Rows.Count > 0 Then
If storedHeaders.Length - 1 >= i Then
If headers(i) = storedHeaders(i) Then
If storedMapToFields.Length - 1 >= i Then
headerId = Convert.ToInt32(storedMapToFields(i))
End If
End If
End If
End If
%>
<select class="fontOnly" id="mapfield<%=i%>" style="width: 115px;" name="mapfield<%=i%>" onchange="">
<%--=selectOptions--%>
<option value="0">-- No mapping --</option>
<%
For Each row As DataRow In contactFields.Tables(0).Rows
If dt.Rows.Count > 0 Then
If storedHeaders.Length - 1 >= i Then
If storedMapToFields.Length - 1 >= i Then
If headerId = row("FieldID") Then%>
<option value="<%=row("FieldID")%>" selected>
<%=row("Label")%></option>
<%Else%>
<option value="<%=row("FieldID")%>">
<%=row("Label")%></option>
<%End If%>
<%Else%>
<option value="<%=row("FieldID")%>">
<%=row("Label")%></option>
<%End If%>
<%Else%>
<option value="<%=row("FieldID")%>">
<%=row("Label")%></option>
<%End If%>
<%Else%>
<option value="<%=row("FieldID")%>">
<%=row("Label")%></option>
<%End If%>
<%Next%>
</select>
</td>
<% If dt.Rows.Count > 0 Then
If storedHeaders.Length - 1 >= i Then%>
<%If Not storedMatch(i) = "-1" Then%>
<td class="fontOnly" width="110" align="center">
<input type="checkbox" id="match<%=i%>" name="match<%=i%>" value="<%=storedMatch(i)%>" checked="checked"
onclick="ChangeMatchCheckboxValue('<%=i%>');" />
</td>
<%Else%>
<td class="fontOnly" width="110" align="center">
<input type="checkbox" id="match<%=i%>" name="match<%=i%>" value="1" onclick="ChangeMatchCheckboxValue('<%=i%>');" />
</td>
<%End If%>
<%Else%>
<td class="fontOnly" width="110" align="center">
<input type="checkbox" id="match<%=i%>" name="match<%=i%>" value="1" onclick="ChangeMatchCheckboxValue('<%=i%>');" />
</td>
<%End If%>
<%Else%>
<td class="fontOnly" width="110" align="center">
<input type="checkbox" id="match<%=i%>" name="match<%=i%>" value="1" onclick="ChangeMatchCheckboxValue('<%=i%>');" />
</td>
<%End If%>
<% If dt.Rows.Count > 0 Then
If storedHeaders.Length - 1 >= i Then%>
<%If Not storedUpdate(i) = "-1" Then%>
<td class="fontOnly" width="110" align="center">
<span id="updateGrp" name="updateGrp" style="visibility: hidden;">
<input type="checkbox" id="update<%=i%>" name="update<%=i%>" value="<%=storedUpdate(i)%>" checked="checked"
onclick="ChangeUpdateCheckboxValue('<%=i%>');" /></span>
</td>
<%Else%>
<td class="fontOnly" width="110" align="center">
<span id="updateGrp" name="updateGrp" style="visibility: hidden;">
<input type="checkbox" id="update<%=i%>" name="update<%=i%>" value="1" onclick="ChangeUpdateCheckboxValue('<%=i%>');" /></span>
</td>
<%End If%>
<%Else%>
<td class="fontOnly" width="110" align="center">
<span id="updateGrp" name="updateGrp" style="visibility: hidden;">
<input type="checkbox" id="update<%=i%>" name="update<%=i%>" value="1" onclick="ChangeUpdateCheckboxValue('<%=i%>');" /></span>
</td>
<%End If%>
<%Else%>
<td class="fontOnly" width="110" align="center">
<span id="updateGrp" name="updateGrp" style="visibility: hidden;">
<input type="checkbox" id="update<%=i%>" name="update<%=i%>" value="1" onclick="ChangeUpdateCheckboxValue('<%=i%>');" /></span>
</td>
<%End If%>
</tr>
<% Next%>
</table>
<p> </p>
<br>
<a href="#" onclick="alert('it work !!!!');UpdateContacts();return false;"><img border="0" src="../images/Buttons/next.png" /></a>
</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
</html>
Try this to catch the error :
(what's your favorite browser?)
(what's your favorite browser?)
function UpdateContacts() {
try {
alert('Update Contacts');
var mode = document.forms[0].mode.value;
alert(mode );
var count = 0;
var isValid = false;
if (mode == "update") {
alert('mode == update');
var els = document.getElementsByTagName("input");
for (var i = 0; i < els.length; i++) {
if ((els[i].type == "checkbox") && (els[i].name == "match" + count)) {
count++;
if (els[i].checked) {
isValid = true;
break;
}
}
}
}
else {
alert('else');
var els = document.getElementsByTagName("select");
alert(els);
for (var i = 0; i < els.length; i++) {
alert('for loop');
if (els[i].name != "userlist")
count++;
}
if (count == document.forms[0].count.value)
isValid = true;
}
alert('is Valid Fn');
if (isValid) {
if (document.getElementById("SaveMappingForNextImport").checked) {
document.forms[0].SaveMapping.value = "Save";
if (document.getElementById("importMode").checked) {
document.forms[0].ImportUpdateFlag.value = "Import";
} else {
document.forms[0].ImportUpdateFlag.value = "Update";
}
//document.forms[0].submit();
}
//else {
document.forms[0].action = "IUW_Step3.aspx";
document.forms[0].submit();
//}
}
else {
if (mode == "update")
alert("You must select at least one column to match records for updating.");
}
}
catch(e) {alert(e);}
}
ASKER
the problem is with document.forms[0].count.va lue
it is grabing 10 but should get only 8 I'm not sure where it is getting 10 from
Is there anyway I can change it ?
it is grabing 10 but should get only 8 I'm not sure where it is getting 10 from
Is there anyway I can change it ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Was this executed, this "alert('Update Contacts');" inside UpdateContacts function? If not, there must be a syntax error because if everything is coded well, "alert('Update Contacts');" should execute. If you're using Internet Explore you can easily identify if the javascript is working or not because it will display a warning icon at the bottom left of the browser.
<a href="#" onclick="alert('it work !!!!');UpdateContacts();return false;"><img border="0" src="../images/Buttons/nex