Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    I want to save this vb script form in local drive after all the input have keyed-in..

    I want to save the input form in csv or xml format in local drive...How can i do that?

    Code:
    <html><head><script language="VBScript">count=2Sub doAddRow()   Dim oTbl, oRow, oCell   Set oTbl=document.getElementById("mytable")   Set oRow = oTbl.insertRow    Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Lot Number' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Location' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Total In' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='1 * Test' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='2 * Test' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='3 * Test' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Total Out' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Lot Status' type='text' id='Lot Number"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Remark' type='text' id='Lot Number"&count&"' value='' />"
    count = count+1End Sub
    Sub deleteRow()Dim oTbl, oRowSet oTbl=document.getElementById("mytable")
    if count>2 thenoTbl.deleteRow(count-1)count = count -1end if
    End sub
    Sub doAddRow2()   Dim oTbl, oRow, oCell   Set oTbl=document.getElementById("mytable2")   Set oRow = oTbl.insertRow    Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Entry' type='text' id='Entry"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Down' type='text' id='Entry"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Up' type='text' id='Entry"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Failure Mode/Action/Remark' size=40 type='text'  id='Entry"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='D/T' type='text' id='Entry"&count&"' value='' />"   Set oCell = oRow.insertCell   oCell.innerHTML= "<input name='Attended By' type='text' id='Entry"&count&"' value='' />"   count = count+1End Sub
    Sub deleteRow2()Dim oTbl, oRowSet oTbl=document.getElementById("mytable2")
    if count>2 thenoTbl.deleteRow(count-1)count = count -1end if
    End sub
    Sub saveFile()Dim txtPathDim txtName
    txtPath = "C:\Shared Folder\Emp InfoPath Forms"txtName = "form1.xml"
    XDocument.SaveAS(txtPath & txtName)End sub
    </script></head><body>
    
    <form='form1' action="#" method="get"><div id ="myOutput" style="border:2px solid black">
    TESTER  <input type="text"/>                                            DATE  <input type="text" />             EMP NO  <input type="text" />   6S DONE  <input type="text" />
    <br /><br />
    WW  <input type="text" size="8"maxlength="8"/>          NAME  <input type="text" />             SHIFT  <input type="text" />
    <br /><br /><br />
    PASSOVER (Please verify Summit Receipe & Storm before start shift)
    <br /><br /><br />
    
     Summit Receipe OK ?                                    <select name="">                                                   <option value="" style="display:none;"></option>               <option value="Yes">Yes</option>                                <option value="No">No</option>                                 </select>                                              
    <br /><br />     Motif/ Storm OK ?                                       <select name="">                                                    <option value="" style="display:none;"></option>               <option value="Yes">Yes</option>                                <option value="No">No</option>                                 </select>                                                    <br /><br /><br />
    <p></p><p></p>
    <table id="mytable" border='1'>      <tr><td><center>Lot Number</center></td>   <td><center>Location</center></td>      <td><center>Total In</center></td>      <td><center>1 * Test</center></td>      <td><center>2 * Test</center></td>      <td><center>3 * Test</center></td>      <td><center>Total Out</center></td>     <td><center>Lot Status</center></td>    <td><center>Remark</center></td></tr>     <TR>       <TD> <input name="Lot Number" type="text" id="Lot Number" /></TD>       <TD> <input name="Location" type="text" id="Location" /></TD>       <TD> <input name="Total In" type="text" id="Total In" /></TD>       <TD> <input name="1 * Test" type="text" id="1* Test" /></TD>       <TD> <input name="2 * Test" type="text" id="2 * Test" /></TD>       <TD> <input name="3 * Test" type="text" id="3 * Test" /></TD>       <TD> <input name="Total Out" type="text" id="Total Out" /></TD>       <TD> <input name="Lot Status" type="text" id="Lot Status" /></TD>       <TD> <input name="Remark" type="text" id="Remark" /></TD>      </TR>   </table><br />
    <INPUT TYPE="button" value="Add" onclick="doAddRow()"><INPUT TYPE="button" value="Delete" onclick="deleteRow()">
    </p><p></p>
    <table id="mytable2" border='1'>      <tr><td><center>Entry</center></td>       <td><center>Down</center></td>  <td><center>Up</center></td>    <td><center>Failure Mode/Action/Remark</center></td>    <td><center>D/T</center></td>   <td><center>Attended By</center></td></tr>     <TR>       <TD> <input name="Entry" type="text" id="Entry" /></TD>       <TD> <input name="Down" type="text" id="Down" /></TD>       <TD> <input name="Up" type="text" id="Up" /></TD>       <TD> <input name="Failure Mode/Action/Remark" type="text" id="Failure Mode/Action/Remark" size="40" /></TD>       <TD> <input name="D/T" type="text" id="D/T" /></TD>       <TD> <input name="Attended By" type="text" id="Attended By" /></TD>     </TR> </table><br />
    <INPUT TYPE="button" value="Add" onclick="doAddRow2()"><INPUT TYPE="button" value="Delete" onclick="deleteRow2()">
    </div>
    <INPUT TYPE="button" value="Save" onclick="saveFile()">
    </form>
    </body></html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,422 Times in 4,387 Posts
    Are you aware that:

    (1) Your question has *NOTHING AT ALL* to do with ASP. ASP runs on the server. You are wanting code that runs on the client, in the browser.

    (2) If you save the data on the local system, it will only be available on that system. That is, no other users will be able to see it.

    (3) So long as you write using VBScript code in the browser, only people using Microsoft Internet Explorer can use the code.

    (4) In order for the browser (even MSIE) to write data to the local drive, the HTML page *MUST* come from a "Trusted Server". In most cases, this means it will have to come from some inTRAnet server, not across the inTERnet.

    (5) Even coming from a trusted server, the user will have to allow the page to use code that is considered "unsafe for scripting". That is, the user will have to say "OK" or "Yes" when prompted to allow the page to do the unsafe code.

    ***********

    If you are aware of all of the above and still want to proceed, then yes, it can be done.

    CSV willl be easier to create. VBScript doesn't have any built in controls to make it easy to create XML data.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts
    TQ for the reply.Yes..the security issue wont be a problem because this form will be used internally.which is intranet..I am using IIS server..would you be kind to help me to create a function inside the code which whan i click the save button it will save it to local drive.I just want to try it out to save it 1st,then i will enchance it...how can we do like what u have mention in number (5) comment...

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,422 Times in 4,387 Posts
    .I am using IIS server...
    No, you are not.

    This has NOTHING WHATSOEVER to do with IIS.

    Unless you mean that EVERY PERSON USING THIS will be running IIS on HIS/HERE PERSONAL MACHINE, then IIS has nothing to do with this.

    One more time: WHEN YOU USE SCRIPT IN THE BROWSER, this has *NOTHING* to do with IIS.

    ***********

    One more important question: *HOW* will you know *WHERE* to save the data on the user's machine???

    Presumably, every user has DIFFERENT FILES and DIFFERENT DIRECTORIES on his/her machine. If you try to save this into a particular directory (example: C:\SavedFormData) what happens if the directory does NOT EXIST on some user's machine?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bheema (12-18-2012)

  • #5
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I will be given the path to save it in specific share folder...But do you think it is possible?..I think it would be such a waste of space and it is complicated if each and every time the click save,it save save the form which in a long time will use up some amount of space..Need your opinion and advice on this because I am an intern and i was told to do like this.So,If i can enhance this,it will be better.Is it possible to connect with database?And how shall i submit this form to database?Please give me an example on how to do that?TQ

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,422 Times in 4,387 Posts
    Well, you *COULD* always OVERWRITE the file in the shared folder. So the file might grow, but there could be only one file, if you wished.

    However...

    Your instinct to use a database is MUCH MUCH BETTER IDEA!!! Good for you!

    Now you WOULD use IIS on a webserver. And yes, you COULD use ASP code (written in VBScript, so you don't have to learn another language right now) to do this.

    You could save the data in one or more tables in a SQL Server or MySQL or Access database (in order of choice). You could have a field in the table(s) that tells who owns the particular data, so that when a user comes back to the page you could, if they wanted you to, re-load the data from the DB. More than that, any administrator with proper permissions could look at ANY of the records in the table(s) and so view what any person in the company has saved, if that is at all desirable.

    **********

    If your boss insists, then yes, you could do this all in the browser. But your idea is, I think, at least 10 times better.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bheema (12-18-2012)

  • #7
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you for the explanation..But can u show me an example how could i save this whole form which has table that the row is added according to the need of the user...I a beginner so it would be better if u can show me some examples which i can use it as a reference...TQ man..N sorry for the trouble...

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,422 Times in 4,387 Posts
    I can't give you a full course in writing ASP code here and now. You need to go learn *SOME* things on your own.

    You might start here:
    http://www.w3schools.com/asp/default.asp

    I will tell you that if you are trying to save <form> fields to a database with ASP code (or, for that matter, even if you want to save them to a logal file!) you are much better off using *NAMES* that are incremented by a counter and FORGET ABOUT THE IDs!

    Form fields do not, in general, need IDs. So don't use them when you don't need them.

    And for the field names, I recommend that you use names that VBScript will *recognize* as names.

    So... Here, for example, is my rewrite of one of your functions:
    Code:
    Sub doAddRow()   
       Dim oTbl, oRow, oCell
       Set oTbl=document.getElementById("mytable")
       Set oRow = oTbl.insertRow
       Set oCell = oRow.insertCell
       oCell.innerHTML= "<input name='Lot_Number_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Location_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Total_In_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Test_1star_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Test_2star_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Test_3star_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Total_Out_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Lot_Status_" & count & "' />"
       Set oCell = oRow.insertCell   
       oCell.innerHTML= "<input name='Remark_" & count & "' />"
       count = count+1
    End Sub
    Now, in your ASP code, you can easily pull the data from all those rows, based on the row count.

    Example:
    Code:
    <%
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "...you will need to supply a connection string here..."
    
    Set RS = Server.CreateObject("ADODB.Recordset")
    RS.Open "yourDbTableName", conn, 3, 3
    
    userid = Session("UserId") ' I won't explain this now...read some tutorials first
    
    For count = 1 To 9999
        lotnum = Trim(Request("Lot_Number_" & count))
        If lotnum = "" Then Exit For ' no more data from form
    
        RS.AddNew ' add a record to the db
        RS("userid") = userid ' say who this record belongs to
        RS("Lot_Number") = lotnum
        RS("Location") = Trim(Request("Location_" & count))
        RS("Total_In") = Trim(Request("Total_In_" & count))
        RS("Test_1star") = Trim(Request("Test_1star_" & count))
        RS("Test_2star") = Trim(Request("Test_2star_" & count))
        RS("Test_3star") = Trim(Request("Test_3star_" & count))
        RS("Total_Out") = Trim(Request("Total_Out_" & count))
        RS("Lot_Status") = Trim(Request("Lot_Status_" & count))
        RS("Remark") = Trim(Request("Remark_" & count))
     
        RS.Update
    
    Next ' go get another row
    RS.Close
    conn.Close
    %>
    But this is getting ahead of you. Way ahead of you. First you have to create the database then create the table that will hold this data. And so on and so on.

    You have several weeks of learning ahead of you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bheema (12-19-2012)

  • #9
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts
    TQ so much man...will work on it..


  •  

    Tags for this Thread

    Posting Permissions

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