Link to home
Start Free TrialLog in
Avatar of trojan_uk
trojan_uk

asked on

splitting textfield and checkbox array

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
Avatar of lrygiel
lrygiel
Flag of United States of America image


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
Avatar of trojan_uk
trojan_uk

ASKER

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
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
One correction. The line should be
       PersonalAry = split(Request.Form("chkSelected"),",").
I missed a paren.
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
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.




ASKER CERTIFIED SOLUTION
Avatar of lrygiel
lrygiel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Lee many thanks for your help, it works a treat now