Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

splitting textfield and checkbox array

Posted on 2007-10-15
8
Medium Priority
?
281 Views
Last Modified: 2011-09-20
Hi,

I have a form which is built dynamically from a recordset from SQL server. The number of results may vary but have the following format. In a table, column 1 displays a telephone number, column 2 displays a textfield (description) that the user adds adds their description to, column 3 holds a checkbox (mark_number) that holds the number that is displayed in column 1.

The idea is that the user can check any of the numbers they are marking as personal, so they enter a value in the description field and check the box, any number marked gets added to a SQL table combining the texfield and the checkbox values.

My question is what is the best way to tie a textfield and checkbox together and pass the values to a Stored Procedure, normally I would split say the description field array using the Split function but I'm not sure how to get both description and mark_number values tie together. And also is it best to split before passing to SP within the ASP or split in the SP using SQL
Thanks
0
Comment
Question by:trojan_uk
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:lrygiel
ID: 20078549

Try assigning a ascending sequential number to each checkbox value and use that number as a suffix to the phone and description textbox names. For example:




<% WITHIN SOME LOOP STRUCTURE %>

      i = i + 1 %>

      <tr>
            <TD><input type='text' name='txtPhone<%=i%>' value=''></TD>
            <TD><input type='text' name='txtDesc<%=i%>' value=''></TD>
            <TD><input type='checkbox' name='chkSelected' value='<%=i%>'></TD>
      </tr>


This way the result will be something like this:

      <tr>
            <TD><input type='text' name='txtPhone1' value=''></TD>
            <TD><input type='text' name='txtDesc1' value=''></TD>
            <TD><input type='checkbox' name='chkSelected' value='1'></TD>
      </tr>
      <tr>
            <TD><input type='text' name='txtPhone2' value=''></TD>
            <TD><input type='text' name='txtDesc2' value=''></TD>
            <TD><input type='checkbox' name='chkSelected' value='2'></TD>
      </tr>

<% END LOOP %>

( IF NOT IN A LOOP PROCESS,  JUST ASSIGN THEM DIRECTLY)

On the receiveing end then all you need to do is handle the contents of the 'checkSelected' field to determine which ones selected. If the request.querystring("checkSelected") contains:

      1,4,18,9

then you know that the checkbox associated with:

      Request.QueryString("txtDesc1"),
      Request.QueryString("txtDesc4"),
      Request.QueryString("txtDesc18"),
      Request.QueryString("txtDesc9"),

was Checked.
 
I hope that makes sense.

Lee
0
 

Author Comment

by:trojan_uk
ID: 20085060
Hi Lee,

Thanks for your reply. I did try that method but what I can't figure out is how to tie them together in a SP.

So if I select 4 numbers using your sugestion

description1(bert)
description2(fred)
description3(bill)
description4(john)


mark_number1(11111111111)
mark_number2(22222222222)
mark_number3(33333333333)
mark_number4(44444444444)

how would I pass this into an SP, I guess I would have to loop through the insert, but what I need help on is how to tie description1 and mark_number1 together on insert?

Hope I'm making sense

Many thanks
0
 
LVL 4

Expert Comment

by:lrygiel
ID: 20085409
trojan_uk:


Suppose this is your form:

<form method="Post">
      <Table>      
            <tr>
                  <TD>Phone: <input type='text' name='txtPhone1' value='1111111111'></TD>
                  <TD>Desc: <input type='text' name='txtDesc1' value=''></TD>
                  <TD>Personal: <input type='checkbox' name='chkSelected' value='1'></TD>
            </tr>
            <tr>
                  <TD>Phone: <input type='text' name='txtPhone2' value='2222222222'></TD>
                  <TD>Desc: <input type='text' name='txtDesc2' value=''></TD>
                  <TD>Personal: <input type='checkbox' name='chkSelected' value='2'></TD>
            </tr>
            <tr>
                  <TD>Phone: <input type='text' name='txtPhone3' value='3333333333'></TD>
                  <TD>Desc: <input type='text' name='txtDesc3' value=''></TD>
                  <TD>Personal: <input type='checkbox' name='chkSelected' value='3'></TD>
            </tr>
            <tr>
                  <TD>Phone: <input type='text' name='txtPhone4' value='4444444444'></TD>
                  <TD>Desc: <input type='text' name='txtDesc4' value=''></TD>
                  <TD>Personal: <input type='checkbox' name='chkSelected' value='4'></TD>
            </tr>

      </table>
      <INPUT type="submit" value="submit" name="submit">
</form>


I want the First and Third rows to be marked as Personal, so I enter a descripton and check the boxes in those rows (in 1 and 3).

On the receiving end here is what I would do:

<%

      sub CallStoredProcedure(strPhone, strDesc)
            .....
      end sub

      Dim PersonalAry
      PersonalAry = split(Request.Form("chkSelected",",")
      Dim i
      for i = 0 to UBOUND(PersonalAry)
            callStoredProcedure (Request.Form("txtPhone" & i), Request.Form("txtDesc" & i)
      Next

%>

First I place the contents of the chkSelected into an array, this will onlu contain the values of the rows I checked (in out example that's 1,3).
Second I use the values in the array to identify to a sub routine the Phone and Desc variables to process. The iteration of the loop will cause the following:

      Pass 0:    callStoredProcedure (Request.Form("txtPhone1"), Request.Form("txtDesc1")
      Pass 1:    callStoredProcedure (Request.Form("txtPhone3"), Request.Form("txtDesc3")

I hope that makes sense.

Lee
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:lrygiel
ID: 20085428
One correction. The line should be
       PersonalAry = split(Request.Form("chkSelected"),",").
I missed a paren.
0
 

Author Comment

by:trojan_uk
ID: 20100665
Hi lrygiel,

sorry for the dealy I have been away for the last couple of days.

I have tried you idea but for some reason the first fileds are blank:

ASP*********************************************************

sub CallStoredProcedure(strPhone, strDesc)
        
szSQL="EXEC dbo.wbMobPersonalNumberingAdd @MOBDEVID = " & Request.Form("mobdevid") &_
      ", @PERSONAL_NUMBER ='" & strPhone &_
      "', @DISPLAY_NAME ='" & strDesc &_                   
      "', @INVNUMBER ='" & Request.Form("invnumber") &_
      "', @EMPID =" & Request.Form("empid") &_
      ", @COMPLETE =" & Request.Form("declared")
            
      objRSite = Conn.Execute (szSQL)
                                     
      end sub

      Dim PersonalAry
      PersonalAry = split(Request.Form("check"),",")
      Dim i
      for i = 0 to UBOUND(PersonalAry)
            callStoredProcedure Request.Form("number" & i), Request.Form("description" & i)
      Next


HTML**********************************************************************


<input type="hidden" name="number1" value="0797*******"/>
<input type="text" name="description1" class="submit"/>
<input type="checkbox" name="check" value="1"  class="submit" />

<input type="hidden" name="number2" value="07976666666"/>
<input type="text" name="description2" class="submit"/>
<input type="checkbox" name="check" value="2"  class="submit" />

<input type="hidden" name="number3" value="07977777777"/>
<input type="text" name="description3" class="submit"/>
<input type="checkbox" name="check" value="3"  class="submit" />

result on response.write:

EXEC dbo.wbMobPersonalNumberingAdd @MOBDEVID = 714, @PERSONAL_NUMBER ='', @DISPLAY_NAME ='', @INVNUMBER ='62007', @EMPID =172, @COMPLETE =1

EXEC dbo.wbMobPersonalNumberingAdd @MOBDEVID = 714, @PERSONAL_NUMBER ='07976666666', @DISPLAY_NAME ='test2', @INVNUMBER ='62007', @EMPID =172, @COMPLETE =1

EXEC dbo.wbMobPersonalNumberingAdd @MOBDEVID = 714, @PERSONAL_NUMBER ='07977777777', @DISPLAY_NAME ='test3', @INVNUMBER ='62007', @EMPID =172, @COMPLETE =1


@PERSONAL_NUMBER  and @DISPLAY_NAME do not have the values, any idea on what I have done wrong
0
 
LVL 4

Expert Comment

by:lrygiel
ID: 20100967
I hope it was pleasure and not business.

You need to change the following line:

     callStoredProcedure Request.Form("number" & i), Request.Form("description" & i)
to

    callStoredProcedure Request.Form("number" & PersonalAry(i)), Request.Form("description" & PersonalAry(i))

You want to append the array(subscript).value and not the subscript to the sub toutine.




0
 
LVL 4

Accepted Solution

by:
lrygiel earned 1000 total points
ID: 20101068
trojan_uk:

One last thing I noticed. The value of Request.Form("check") contains spaces between the comma seperated values, so you want to remove those spaces because you want to end up with an array of integers. This can be accomlished by replacing the "SPLIT" code with the following:

    PersonalAry = split(Replace(Request.Form("check")," ",""),",")

Good Luck:

Lee
0
 

Author Comment

by:trojan_uk
ID: 20108114
Lee many thanks for your help, it works a treat now
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question