0

I have an html select element that, based on a value set elsewhere, is supposed to show one of two pairs of value. In one case, it should be "New" and "Assumed", and in the other "Existing" and "Organic Growth"

So currently I'm creating it with all of them, like so:

<tr>
    <td nowrap align="left" valign="top">
      <font color="<%=Session("TextColor")%>" style="font: 8pt arial">Subcategory:&nbsp;</font>  
        </td>
    <td nowrap align="left" valign="top">
    <select name="subcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
      <option value="3">Organic Growth
      <option value="2">Existing
      <option value="1">Assumed
      <option value="0">New
    </select>
    </td>
</tr>   

But I want to only show two of these values at a time, based on the value of IsNewBusiness:

Dim IsNewBusiness As Boolean

...after this:

currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
    IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()

Knowing the value of IsNewBusiness, how can I specify which pair of items in the html select are visible? Can I add some "inline" javascript or something?

user692942
  • 16,398
  • 7
  • 76
  • 175
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • The answer does restrict the entries to two, and the problem is not with the javascript below, but now I get the same two values every time no matter what; see http://stackoverflow.com/questions/42537661/why-is-my-boolean-not-being-assigned-the-correct-value – B. Clay Shannon-B. Crow Raven Mar 01 '17 at 21:36
  • Both these questions *(this and the linked one)* are part of the same issue. They both refer to ASP.Net likely using VB.Net they are not VBScript or Classic ASP even though the OP is trying to use them as such. – user692942 Mar 29 '17 at 14:55
  • It's working now using the accepted answer; that's why I bountified this - to award the existing answer ASAP. – B. Clay Shannon-B. Crow Raven Mar 29 '17 at 15:03

1 Answers1

2

I'd leave javascript out of it:

<tr>
    <td nowrap align="left" valign="top">
      <font color="<%=Session("TextColor")%>" style="font: 8pt arial">Subcategory:&nbsp;</font>  
        </td>
    <td nowrap align="left" valign="top">
    <select name="subcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
<% if not isNewbusienss then %>
      <option value="3">Organic Growth
      <option value="2">Existing
<% else %>
      <option value="1">Assumed
      <option value="0">New
<% end if %>
    </select>
    </td>
</tr>

Note: My vbscript is very rusty so you may need to iron out some bugs

Jon P
  • 19,442
  • 8
  • 49
  • 72
  • If you can, take a look at http://stackoverflow.com/questions/42537661/why-is-my-boolean-not-being-assigned-the-correct-value – B. Clay Shannon-B. Crow Raven Mar 01 '17 at 21:35
  • This is not VBScript, the OP has posted ASP.Net code likely using VB.Net, someone needs to teach them about MVC or at the very least the concept of a Postback. – user692942 Mar 29 '17 at 14:53
  • MVC is out of the question for this; my mandate is to simply add some functionality to an existing (olde-fashioned) site/app - that's it, nothing else, nothing new, nothing fancy. I don't agree with it, but "it is what it is." – B. Clay Shannon-B. Crow Raven Mar 29 '17 at 15:01
  • @B.ClayShannon The code seems to be an unholy amalgamation of COM-based code used by VBScript but in an ASP.Net environment and you wonder why you are having problems. This is a classic example how **NOT** to migrate a Classic ASP website to ASP.Net. – user692942 Mar 29 '17 at 15:25
  • Okay, this is the last I will say on this: I am not migrating it, just adding some functionality. I admit it's a complete mess, and it was the final straw in my decision to seek other opportunities. – B. Clay Shannon-B. Crow Raven Mar 29 '17 at 15:28
  • That's fine, we all have projects like that I just want to be clear that assuming this is VBScript is incorrect. They may share certain syntax but VB.Net and ASP.Net are different technologies to VBScript and Classic ASP. It works in this instance because the change is minor, but tagging as [tag:vbscript] just means people make the wrong assumptions about your code. – user692942 Mar 29 '17 at 15:51