ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 12th, 2003, 02:15 AM
spincycler spincycler is offline
 
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Brisbane
Posts: 15 spincycler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 "&nbsp;" & 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%">&nbsp;&nbsp;&nbsp;</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>&nbsp;</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>&nbsp;</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.

Reply With Quote
  #2  
Old June 12th, 2003, 07:55 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 13 m 21 sec
Reputation Power: 76
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

Reply With Quote
  #3  
Old June 12th, 2003, 08:00 AM
spincycler spincycler is offline
&nbsp;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Brisbane
Posts: 15 spincycler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks, but I've tried that!

Code:

for i = counter to UBound(cardArray)
	response.write "&nbsp;" & i & " = " & CStr(cardArray(i)) & "&nbsp;" & "<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.

Reply With Quote
  #4  
Old June 12th, 2003, 08:25 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 13 m 21 sec
Reputation Power: 76
well, it looks like you know this better than me, so i'll just say good luck!

Reply With Quote
  #5  
Old October 8th, 2003, 02:17 PM
eanicklaus eanicklaus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Florida
Posts: 21 eanicklaus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Prepopulating form checkboxes..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT