Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBScript after Form input

    I want to update an Access table via a web page. I'm displaying the table initially in a table using
    <form name="form2" etc....>
    <%dim intCount
    intCount=1
    RS.MoveFirst
    While Not RS.EOF
    %>
    <tr><td><input value="<%=RS("Target Release Date")%>" type="text" width="90" name=<%="treldate" & intCount%> /></td></tr>
    <%
    intCount = intCount + 1
    RS.MoveNext
    Wend
    %>
    etc..... (I know I've omitted quite a bit, but this bit works ok.)

    In other words, I'm assigning the form field names as "treldate1", "treldate2" etc. All well and good - but how do I refer to them in the OnClick event in VBScript?

    So far, I have:
    RS.Open
    intCount = 1
    RS.MoveFirst
    while not RS.EOF
    RS.Edit
    RS("Target Release Date") = form2.treldateX.value
    RS.Update
    RS.MoveNext
    intCount = intCount + 1
    wend
    RS.close
    Set RS = Nothing

    But I don't know how to vary the "form2.treldateX.value" to replace the X with the value of intCount; i.e. a string like - "treldate" & intCount. I just don't know how to accomplish this in VBScript. Does anyone have any ideas and can come up with the solution? Or even a different way of doing this task?

    Thanks in advance.

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    Keith,

    You're on the right track. You can use Request.Form("FieldName") to read a value from a form variable.

    Replace your line:
    RS("Target Release Date") = form2.treldateX.value
    with:
    RS("Target Release Date") = Request.Form("treldate" & X)

    Post back if that doesn't do the trick.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    Hi Mark,

    Thanks for the suggestion, which sounds good to me. I'm rather new at all this malarky, and I'm told that the only trouble with your answer is that the VBScript OnClick subroutine is actually in the ASP page that is displayed on the client side. Thus the OnClick is actioned in the client and not the server where the Request.Form() would be relevant (am I making sense?). So I need to be able to action the database update in the server, not in the client. So-o-o-o-o, the OnClick just needs to tell the server that the Submit button has been pressed, so that some VBScript runs in the ASP only if that is true, this updating the database records, finally refreshing the page (am I still making sense?)? Do you see my point? Thanks for the reply though - it's got me thinking!!

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    There are several ways to handle situations like this, but all of them involve posting a page back to the server (where the database update will ultimately happen). You can post a page back to itself (form action="currentpage.asp") or you can post it to another form (form action="differentpage.asp"). In either case, the receiving page will contain the logic to validate the data, perform any necessary data updates, and any final actions (i.e. message that update was successful or displaying of updated data).

    If you choose to use the same page for entry and display, you'll need to write logic to determine what "state" the page should be in (i.e. either enter or update/display). Otherwise, it's usually easier to handle this with separate pages.

    Just to give you something *else* to think about - If you have the flexibilty of choosing a web platform, I would highly recommend taking a look at .NET rather than classic ASP. There are a host of benefits with .NET and very few down-sides. Of course, if you're locked into classic ASP, no worries...

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    Thanks for that, Mark, and your ideas confirm what I've been heading towards, albeit tentatively! I think I'll have to allow the user to 'click' on a record, thus triggering a display of another page with the record's fields for update. After update this page will perform the database update then return to the first page. There won't be many updates anyway, so it won't be inefficient. Thanks for all your help. It's always good for a novice like myself to have his ideas confirmed or steered back on course! Thanks again.

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    Hi Mark,

    Can I take up a little more of your time and good will? The problem I had before has been solved by doing precisely what you suggested and I'm now allowing the user to click the record id on the initial page, taking me to an update page where the record is displayed for update - except for the record id itself. The fields are displayed in inputs inside a form and when the user presses the Submit button, it triggers a VBScript within the page to update the database.

    My query concerns the fact that in order to pass the Record Id to the VBScript, I am making it a disabled input text field within the form, so that I can refer to it within the script, e.g. form1.RecId. However, this looks a little clumsy, and I'd rather display the field as a simple text field without it looking as though somehow it could be updated, i.e. within a text box. Is there a way of doing this? Again, I think my inexperience in this area is letting me down.

    Thanks in advance.

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    Yes, absolutely!

    You can print the RecordId as simple text (<%=RS("RecId")%>), then include a hidden form field for purposes of collecting the RecordId on postback (<input type="hidden" value="<%RS("RecId")%>".....>)

    (Double check my syntax because it's been many (MANY) months since I've written classic ASP script.)

    Also, be aware that there is a small security risk involved when relying on hidden form fields to update data. It's possible for a user to save a local copy of the page, modify the values of the hidden tags, then repost the bogus values to your database. You may also consider storing the RecordId in a Session variable to persist it between posts, in addition to writing the value on the page for the user to see. Then you can remove the session variable when you're finished with the update.

  8. #8
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    Hey, thanks, Mark, for such a speedy reply! And a quick look up of hidden controls gives me all I need.Told you it was my inexperience! Thanks again. You're a star.

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBScript after Form input

    You're quite welcome! I'm glad to help.

    I'm not sure if you've invested in a reference book for web programming, but let me make a few recommendations.

    There was a lively discussion in this board a couple of years ago that produced several great references to books and websites. You'll find that info starting with <post#=193323>post 193323</post#> and continuing throughout the thread.

    Enjoy!

Posting Permissions

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