I am encountering issues with my if
, else
, and else if
statements.
Here is the code snippet in question:
function draw(d) {
var testarray = JSON.parse(a);
var testarray1 = JSON.parse(a1);
var testarray2 = JSON.parse(a2);
var Yaxis = $("#<%=hidden10.ClientID%>").val();
if (d == 1)
{
var c = testarray;
Yaxis = 'data';
}
else if (d == 1)
{
var e = testarray1;
Yaxis = 'data1';
}
else if (d == 2)
{
var c = testarray;
Yaxis = 'data2';
}
else if (d == 2)
{
var e = testarray1;
Yaxis = 'data3';
}
else(d == 3)
{
var e = testarray1;
Yaxis = 'data4';
}
During debugging, it seems that the code only recognizes d==1
and then jumps to d==3
without executing for 1
and 2
. The values of yaxis
only show up as data4
, omitting data
, data1
, and data2
on the graph.
The issue might be related to the incorrect implementation of my else
statement. I have referred to a resource about JavaScript conditionals but still couldn't resolve it.
d
corresponds to a radio button fetched from the VB.NET backend:
Select Case RadioButtonList1.SelectedItem.Value
Case 1
Dim Yaxis As String
If RadioButtonList1.SelectedItem.Value = 1 Then
Yaxis = "data"
End If
hidden10.Value = Yaxis
For Each row In Year1
testarray.Add(row("kWh"))
Next row
Dim arrayJsonTest1 As String = serializer1.Serialize(testarray)
Dim arrayJson11 As String = serializer1.Serialize(testarray1)
hidden.Value = arrayJsonTest1
hidden1.Value = arrayJson11
hidden2.Value = arrayJson12
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType, "draw", "javascript:draw(1);", True)