|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Prepopulating form checkboxes..
Hi I've got a bunch of string values in a session variable that I want to split into an array and use to conditionally 'check' some checkboxes.
My VbScript.. Code:
<%
' // Session("merchantCards") contains a dynamic array of values like "MC,VISA,BC"
cardArray = Split(Session("merchantCards"),",")
for i = LBound(cardArray) to UBound(cardArray)
currentCardType = ""
response.write " " & i & " = " & cardArray(i) & "<br>"
if CStr(cardArray(i)) = CStr("MC") then
valueMC = "checked"
elseif CStr(cardArray(i)) = CStr("Diners") then
valueDiners = "checked"
elseif CStr(cardArray(i)) = CStr("VISA") then
valueVISA = "checked"
elseif CStr(cardArray(i)) = CStr("AMEX") then
valueAMEX = "checked"
elseif CStr(cardArray(i)) = CStr("BC") then
valueBC = "checked"
elseif CStr(cardArray(i)) = CStr("JCB") then
valueJCB = "checked"
end if
next
%>
I then want to use the 'valueXXX' (eg: valueMC = "checked") string to pre-check some check boxes... Code:
<table width="100%" border="0" cellpadding="0" bgcolor="#EEEEEE">
<tr>
<td width="6%"><input type="checkbox" name="merchantCard" value="MC" <%= valueMC %> ></td>
<td width="34%">MasterCard</td>
<td width="4%"> </td>
<td width="3%"><input type="checkbox" name="merchantCard" value="Diners" <%= valueDiners %>></td>
<td width="53%">Diners Club</td>
</tr>
<tr>
<td><input type="checkbox" name="merchantCard" value="VISA" <%= valueVISA %>></td>
<td>VISA</td>
<td> </td>
<td><input type="checkbox" name="merchantCard" value="AMEX" <%= valueAMEX %>></td>
<td>American Express</td>
</tr>
<tr>
<td><input type="checkbox" name="merchantCard" value="BC" <%= valueBC %>></td>
<td>BankCard</td>
<td> </td>
<td><input type="checkbox" name="merchantCard" value="JCB" <%= valueJCB %>></td>
<td>JCB</td>
</tr>
</table>
What I'm finding is the 'for' loop does the right thing, that is, it loops through each value in the array, but my 'if' statement seems to execute once and drop out, that is, it only sets the first "checked" value it finds and not the rest (if there's multiple values selected in the form) Any ideas on what I'm doing wrong? Ta, Jb. |
|
#2
|
||||
|
||||
|
the way you have nested your If statements means as soon as one is true, it skips the rest, because of the "else". try making them all separate "if"s, so it will skip all that do not apply, but will execute all that do
|
|
#3
|
|||
|
|||
|
thanks, but I've tried that!
Code:
for i = counter to UBound(cardArray)
response.write " " & i & " = " & CStr(cardArray(i)) & " " & "<br>"
cardString = CStr(cardArray(i))
if cardString = CStr("MC") then
output = cardArray(i)
valueMC = "checked"
end if
if cardString = CStr("Diners") then
output = cardArray(i)
valueDiners = "checked"
end if
if cardString = CStr("VISA") then
output = cardArray(i)
valueVISA = "checked"
end if
if cardString = CStr("AMEX") then
output = cardArray(i)
valueAMEX = "checked"
end if
if cardString = CStr("BC") then
output = cardArray(i)
valueBC = "checked"
end if
if cardString = CStr("JCB") then
output = cardArray(i)
valueJCB = "checked"
end if
cardString = ""
next
I'm stumped! I've tried everything from passing the current array value into an external function to changing the if to a case statement (which would function exactly as you've described) but to no avail! Jb. |
|
#4
|
||||
|
||||
|
well, it looks like you know this better than me, so i'll just say good luck!
|
|
#5
|
|||
|
|||
|
Did you get it to work??
I was browsing through the forums because of a similar problem and was just wondering if you ever solved the problem. I too have tried everything and can't seem to get it to work. If you did figure it out, would you mind sharing??
Thanks much. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Prepopulating form checkboxes.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|