SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Manipulating a dynamic string in asp javascript

    Hi there everyone,

    I have a dynamic table that generates a table 52 rows by (X) amount of columns, x being the number of records returned from a recordset.

    Within each cell created there are two text boxes one "wk1apt9" and the other "extraSupWk1apt1" - The numbers in bold are dynamic and i need to grab out of that string (textbox name) and use it to query the database for an update command - then the value within that box will be entered into the database.

    Please visit http://www.websitevision.co.uk/strin...asp?accommID=1 to see the form i will be using and then click the submit button to view all the posted data. Hopefully things will become clear!

    As far as string manipulation goes i am pretty much a novice, so any help would be appreciated. I thought about substrings and indexOf etc, but wasn't sure how to implement this as there are two txt boxes.

    Hopefully i will be able to:

    get txtBox type (whether it has a "extraSup" prefix) then,
    get the 2 numbers then
    query the database with the 2 numbers found, making sure they query the right field in the database. then once that record is found (only one will be returned)
    enter the selected textbox value into the record found...into the right field as there are two possibilities depending on whether it has the "extraSup" prefix!
    then loop onto the next form field posted!!!

    Hope this all makes sense -

    Thanks in advance - ally (ZZ)

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    NY, USA
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is actually pretty simple, although you need to answer me one question first, is the 2nd number a subset of the 1st?

    like 1-1...1-2...1-3....2-1...2-2. Not sure if you know what I mean.

  3. #3
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there,

    thanks for the reply, the second number is a subset (i think) but is not going to be a set increment, as they are the IDs of a recordset returned from a query. e.g

    week | apartment
    1 2
    2 2
    3 2
    ..to 53
    1 15
    2 15
    3 15
    ..to 53
    1 17
    2 17
    3 17

    so the weeks are always going to be 1-53 with values for each apartment within each of those.

    Thanks again,
    ally

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    NY, USA
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, since the Request object is an array, you should be able to just loop through it and find the data you need.

    Some code off the top of my head, not 100% sure this will work, but try it

    Code:
    ArrMax = UBound(Request.Form)
    
    For i = 0 to ArrMax - 1
        If Instr(1, Request.Form(i).Name, "extraSup") > 0 Then 'Not sure about the .Name property, but a similar one exists...
              'extraSup found...decode it
        ElseIf Instr(1, Request.Form(i).Name, "wk") > 0 Then 'Other case
              'decode other case
        End If 
    Next
    I think that'll give you an idea to work off of...

  5. #5
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great stuff, thanks for that MrRadic i'll give that a go and post up any results once i've got it working.

    cheers,
    ally zz

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should help also
    Code:
    For Each sItem In Request.Form
    
    	If Instr(1, sItem, "extraSupWk") > 0 Then 
    
    		' dig out the numbers
    		' easiest way is to remove the prefix, then split the string into an array using apt as the delimiter
    		aNumbers = Split(Replace(sItem, "extraSupWk", ""), "apt")
    		
    		' get the formfield value
    		sValue = Request.Form(sItem)
    		
    		' do something
    		Response.Write "The value of extraSupWk " & aNumbers(0) & " apt " & aNumbers(1) & " is " & sValue
    
    	ElseIf Instr(1, sItem, "wk") > 0 Then 
    
    		' dig out the numbers
    		' easiest way is to remove the prefix, then split the string into an array using apt as the delimiter
    		aNumbers = Split(Replace(sItem, "wk", ""), "apt")
    		
    		' get the formfield value
    		sValue = Request.Form(sItem)
    		
    		' do something
    		Response.Write "The value wk " & aNumbers(0) & " apt " & aNumbers(1) & " is " & sValue
    
    	Else
    		' other type of form field
    		
    	End If
    
    Next


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •