Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript for re-writing form field values

    I need to devise a way to loop thru all the form elements and re-write the values in the form of < %=myRS.Fields("<formname>")% >. I can pretty much do the same thing in ASP but I wanted to use a javascript function so I can invoke one time only and use in any form.

    any ideas?

    TIA
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20>

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

    Re: javascript for re-writing form field values

    Steve, what are you trying to accomplish with this? Are you trying to encapsulate functionality on the postback (when iterating through the fields)?

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    what i am trying to accomplish is, take an existing form used to submit data to a database and re-set the values to the form fields so they will re-display data via a db connection. Thus the need to write <%=myRS.Fields("<field name>")%> in the form field value on the copied form.

    What i want is a function that will look at any form I care to operate on and wap thru the fields to reset the value. I am *not* trying to submit the form field data anywhere, just change the value from <blank> to the appropriate ASP for displaying results in a recordset when that is set up.

    HTH!

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

    Re: javascript for re-writing form field values

    Just to make sure I understand correctly: You want to use Javascript to loop through all fields in a form, setting the value to the desired ASP recordset reference, right?

    If I understand this correctly, I think what you may be overlooking here is this: Even with the desired value entered in the form field's value (i.e. <%=myRS.Fields("<field name>")%>) you won't see the server-side results if this is done via client-side Javascript. The ASP block values are only processed with a server-side postback, rendering any client-side code useless for this purpose...

    You could verify this by writing a simple test page that uses Javascript to modify one or two items (rather than looping through all form fields).

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    not sure I understand your objection re. ASP values being processed on a server-side postback. basically I want to write a string into the form field value = "" section of the form field object. Then setup the db connection and the SQL as desired so that the value will be displayed in the form field on running the db connection. In effect, using Javascript (or whatever) to edit the form automatically once, save the file and setup the db connect stuff. not sure why that's not going to work.

    Remember, I'm not using Javascript to do anything interactive to the page and this function isn't meant to be run except the one time. I'm using Javascript because it's portable and is DOM aware and can be invoked.

    I can of course put something together that writes a value to some named form field & I'll try that. The problem is more 'how do I loop thru n number of form fields and write to the value="" section of each one?'

    I've been doing this manually (that is, re-writing the value="" to the ASP recordset) and would rather let the computer handle the boring stuff (as they are so good at that sort of thing!).

    Anyway, I'll try doing something explicit to a form field element in javascript and if all goes well I'll still need to figure out how to touch each element in a loop.

    I appreciate your help in all this!

  6. #6
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    well, silly me! it didn't occur to me I am trying to use a script to write to the file being displayed. you'd have to output a new page to do this. not gonna bother. what i can do is setup the values in an output, copy to notepad and use that to cut-and-paste. not the best, but better than nuthing.

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

    Re: javascript for re-writing form field values

    Ahh - I think I see now. You're trying to eliminate typing during the code creation process, right? That's not such a bad thing... I've done that MANY times!

    Let me share one of my favorite methods, Mail Merge from MS Word:
    - Enter all necessary fields and rows into an Excel spreadsheet (or other desired data source). In this case, you'll probably want your field names from the recordset. Also, keep in mind that different field types require a different syntax (textbox uses value="", dropdown uses selected, etc...). So you may want to create field for that as well...
    - Paste your code into a blank Word document
    - Follow the documentation to create a merge letter from the current document
    - Link to the appropriate data source
    - Add fields in the appropriate place
    - Merge into a new document, view in Normal view to eliminate page breaks, select all, copy
    - Paste into your code editor - Voila!

  8. #8
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    hmmm... well, the html form is rather complex and i am not sure Word will honor the layout.

    the magic would lie somewhere in a coding enviornment that can inspect the html field name and manipulate the value="" to change to the myRS stuff. I tried looking at FrontPage VB and got skeered.

    however, cut-and-paste isn't as terrible as typing [img]/forums/images/smilies/smile.gif[/img]

    here's my source file to do the cut and paste:
    Attached Files Attached Files

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

    Re: javascript for re-writing form field values

    Be sure you paste into Word as plain text (Edit | Paste Special...). Also, be sure you're only working with the repetitive part of your code.

    Since your form is probably not very repetitive, you may just want to partially-cheat: just generate a list of the specific parts of your code that need pasting rather than the entire form. At least this will save you some typing time...

    Or, if you're like me, you'll spend more time on the shortcut than it would have taken for the longer method, just because it's "easier"... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

  10. #10
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    Well, cut and paste from Notepad is dead easy. i am not at all one to trust Word when it comes to breathing on my HTML code. 'sides, it took me all of a few minutes to prep a form via cut and paste. not the 'easiest' but still better than nothing.

    you know, one reason I wanted to figure this out is I have an idea for a webform to db application that can use several tools I've developed to make it easy for someone to turnkey develop a webform to db system with little more knowledge than being able to design the form in HTML. the problem I am wrestling with today is kind of a big part of one aspect of the app, so i'll likely return to it. i think i'll need to work a lot more before it goes anywhere, or maybe i can meet some guru type who has some tricks of his/her own.

    not quitting the day job by any means but it would be nice to see if i could get a little sw side business going!

    Oh, BTW, since you seem to have some free time <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Do you know, or know anyone who might know, about setting up a stored procedure in SQL Server? I have some complex ASP code I need to xfer over and i know next to nada about stored procedures. I posted a question to OrcsWeb and the gurus never responded. It's probably not terribly difficult but I would appreciate some help. any clues?

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

    Re: javascript for re-writing form field values

    Good luck with your packaged application development. If you're planning to build something new I would highly recommend looking into ASP.NET. The vast majority of ASP apps on the market now are only in ASP because they were written prior to ASP.NET. I also hate to imagine how much longer Microsoft will actually support ASP...

    I would never admit to having free time <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    ... but I do know SQL (T-SQL) pretty well. I seem to remember a previous thread where this came up... Since the lounge doesn't have a SQL Forum, let's start the discussion here. We might decide it's best to move to the Access board if it turns into a strict SQL discussion (as opposed to also involving web stuff).

    Bring it on <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  12. #12
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    Yes, I plan to move to ASP.NET real soon now... probably when I move into my new position as a Sys Analyst. I am looking forward to it.

    As for the T-SQL, this may be rather easy:

    I have a table with one-to-many relationships to 6 other tables. I need to run a stored proc to find all records in the ComplainantInfo table that have no matches in any of the other 6 tables. In one ASP page, this outputs to a simple list. In another ASP page, I wrapped the logic into a class module to output a matrix displaying rows for the ComplainantInfo table and any (or no) corresponding records in the other 6 tables. The code I used in ASP is attached.

    The code works fine but is a bit slow. This is a big part of my maintenance plan for the db and I'd like it to run a little faster. Currently, as I have a webserver on my machine I can reset the timeout so the script will work but once things get going it'd be best to not have the maintenance locked into my box.

    I think this should be easy to do in a stored proc and it'd be a good way to learn stored procs. If you have any ideas on how to implement, I'd appreciate it!
    Attached Files Attached Files

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

    Re: javascript for re-writing form field values

    That looks pretty straightforward... I'm sure you'll make it MUCH quicker with SQL than by creating that many recordset objects...

    I'll take a look at this in the next day or so to see what kind of suggestions I can offer.

    In the meantime, you'll want to brush up on your SQL basics. Open the SQL Books Online and read up on the Update statement and using Parameters in Stored Procedures.

    Good luck!

  14. #14
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: javascript for re-writing form field values

    thanks! SQL Books can be a bit hard to follow, and I've been busy with a lot of other things lately... But, I generally learn by doing something concrete, so if you are willing to give me some pointers to get started that will be great!

    <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

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

    Re: javascript for re-writing form field values

    Steve,

    This one is pretty simple as far as SQL goes. I was mistaken to point you toward the Update statement earlier - I did not completely follow your ASP code at the time. Now, I see that you're not updating anything - just reporting on items that have no match in the main Complaint table.

    Here's the gist of what you'll want to do: Select the ComplaintID field from the ComplaintInfo table, LEFT JOIN the child tables on the ComplaintID fields WHERE the child table's ComplaintID field is null. Then, repeat the statment for each table with a UNION operator separating each.

    The SQL code would look like:<pre>CREATE PROCEDURE DisplayUnmatchedComplaintRecords
    AS

    /* Reported_BVS */
    SELECT ComplaintID FROM Complaint_Info c
    LEFT JOIN Reported_BVS r ON c.ComplaintID = r.ComplaintID
    WHERE r.ComplaintID IS NULL

    UNION

    /* Reported_MPI_Audit*/
    SELECT ComplaintID FROM Complaint_Info c
    LEFT JOIN Reported_MPI_Audit r ON c.ComplaintID = r.ComplaintID
    WHERE r.ComplaintID IS NULL

    UNION

    /* Reported_Limited_Gen_Inv*/
    SELECT ComplaintID FROM Complaint_Info c
    LEFT JOIN Reported_Limited_Gen_Inv r ON c.ComplaintID = r.ComplaintID
    WHERE r.ComplaintID IS NULL

    UNION

    /* Reported_StateEmployee */
    SELECT ComplaintID FROM Complaint_Info c
    LEFT JOIN Reported_StateEmployee r ON c.ComplaintID = r.ComplaintID
    WHERE r.ComplaintID IS NULL

    UNION

    /* Reported_TexasYouthCamp */
    SELECT ComplaintID FROM Complaint_Info c
    LEFT JOIN Reported_TexasYouthCamp r ON c.ComplaintID = r.ComplaintID
    WHERE r.ComplaintID IS NULL

    UNION

    /* Reported_ThirdPartyResources */
    SELECT ComplaintID FROM Complaint_Info c
    LEFT JOIN Reported_ThirdPartyResources r ON c.ComplaintID = r.ComplaintID
    WHERE r.ComplaintID IS NULL</pre>

    (just paste that into a blank Stored Procedure)

    You'll be amazed at how much faster this runs than the ASP code you posted. All you'll need to do is return the rows from this stored procedure into the same output list you were generating before.

    Hope this helps!

Page 1 of 2 12 LastLast

Posting Permissions

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