Getting the ID of an element to check existence and pass variables.

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Getting the ID of an element to check existence and pass variables.

    Thanks for the tips Ray!
    Okay I think I can explain better now.
    What my asp page displays are some records from a database table and a
    text box after each record where a user can enter a date. I would like
    to be able to check if a date is entered and if so, send that line of
    information to a new database table where the information will be
    stored. I've read about how VBScript applys an element id to each
    element in a form. And I would like to know if I can use that id to
    call on these elements. Any help would be greatly appreciated and I
    hope I've explained it well.
    Renie83

    I'm trying something like this:

    if request.form("submitTop") <> "" or request.form("submitBottom")<>
    "" then
    // Two submit buttons can be clicked and as long as the user has not
    tried to submit a blank form do this
    Dim x
    for x= 0 to document.myform.elements.length-1 // get the number of
    elements in the form
    if left(document.myform.elements(x).name,3) ="txt" then //
    check to see if it's a text box
    strDel= document.myform.elements(x).name +
    document.myform.elements(x).id //set variable to the element with it's
    id
    if strDel <> " " then //if the element with this id isn't blank
    insert these fields into the database
    sqlD="INSERT INTO EstDelDate (EnteredBy, PO_PT, Line, FormDate,Part#,
    EntryDate, EstDeliveryDate) VALUES ('" & strEmpName & "',
    '" & strPurchase & "', '" & strLine & "', '" & strPDate & "', '"
    & strPartNo & "', '" & Date() & "', '" & strDel & "')"
    // strEmpName is user login
    strPurchase-strPartNo are variables set to the fields taken from
    the first database
    Date() date function
    strDel is my input variable
    end if
    end if
    next
    Cm2.Execute(sqlD)
    end if
    This is what my form kinda looks like:

    do until rs3.eof
    strPurchase = rs3("PURCHASE ORDER NUMBER")
    strLine = rs3("LINE NUMBER")
    strPDate= rs3("PURCHASE DATE")

    // declare variables
    %>
    <tr%>
    <td ><%=rs3("PURCHASE ORDER NUMBER")%></td>
    <td "><%=rs3("LINE NUMBER")%></td>
    <td ><%=rs3("PURCHASE DATE")%></td>
    <td><input type="text" size=10 name="estDel"></td>
    </tr>
    <%
    rs3.movenext
    loop
    Renie83 Guest

  2. Similar Questions and Discussions

    1. Pass the value of a check box to action page
      Hi All, I know this is probably very simple but I can't figure it out. I have a checkbox on my forms page. When a user checks any one of the boxes...
    2. Help with my form. Checking existence of variables
      I have a form which submits to another page. The submission page checks for the existence of some variables. If they don't exist it assigns a...
    3. how to check array element's values if this element isempty
      Hi, How do you check the array elements empty or not. for example, I have array - array , and from array to array has some value, and there...
    4. passing variables from 'select' element in a form
      Hi, I have 2 'select' element in a form. One is populated with a list of names and the other is empty Users can select 1 or more names from the...
    5. Can one pass variables through a selector?
      In article <clund-50F2A4.12443709092003@amstwist00.chello.com>, C Lund wrote: Yes - either use an NSInvocation to perform the call, or call...
  3. #2

    Default Re: Getting the ID of an element to check existence and pass variables.

    Hi Renie83,

    You're mixing up server-side code and client-side code. Request.Form is
    server side, but document.myform.elements.length is client-side. An ASP
    page will no idea what a document is, or what myform is. I suggest
    something like this:

    <FORM method="post" action="somepage.asp">
    <INPUT name="cmdSubmit" type="submit" />
    <TABLE>
    <TR>
    <TD>
    <INPUT name="txtSomething1" type="text" />
    <INPUT name="txtDate1" type="text" />
    <INPUT name="hidID" type="hidden" value="1" />
    </TD>
    </TR>

    <TR>
    <TD>
    <INPUT name="txtSomething2" type="text" />
    <INPUT name="txtDate2" type="text" />
    <INPUT name="hidID" type="hidden" value="2" />
    </TD>
    </TR>

    <TR>
    <TD>
    <INPUT name="txtSomething3" type="text" />
    <INPUT name="txtDate3" type="text" />
    <INPUT name="hidID" type="hidden" value="3" />
    </TD>
    </TR>
    </TABLE>
    <INPUT name="cmdSubmit" type="submit" />
    </FORM>




    Then, on your page that processes this, if I understand right, you want to
    process values only if the date textbox was filled in, do something like:

    Dim aIDs, iCounter, sSQL, sSomething
    aIDs = Split(Request.Form("hidID"), ", ")
    For iCounter = 0 To UBound(aIDs)
    sSomething = Request.Form("txtSomething" & aIDs(iCounter))
    If Request.Form("txtDate" & aIDs(iCounter)) <> "" Then ''date was
    entered
    sSQL = "INSERT INTO [TheTable] ([Something]) VALUES ('" & sSomething
    & "');"
    Cm2.Execute sSQL
    End If
    Next


    Ray at home





























    "Renie83" <renie83@lycos.com> wrote in message
    news:8e153bdf.0307141412.12deffb0@posting.google.c om...
    > Thanks for the tips Ray!
    > Okay I think I can explain better now.
    > What my asp page displays are some records from a database table and a
    > text box after each record where a user can enter a date. I would like
    > to be able to check if a date is entered and if so, send that line of
    > information to a new database table where the information will be
    > stored. I've read about how VBScript applys an element id to each
    > element in a form. And I would like to know if I can use that id to
    > call on these elements. Any help would be greatly appreciated and I
    > hope I've explained it well.
    > Renie83
    >
    > I'm trying something like this:
    >
    > if request.form("submitTop") <> "" or request.form("submitBottom")<>
    > "" then
    > // Two submit buttons can be clicked and as long as the user has not
    > tried to submit a blank form do this
    > Dim x
    > for x= 0 to document.myform.elements.length-1 // get the number of
    > elements in the form
    > if left(document.myform.elements(x).name,3) ="txt" then //
    > check to see if it's a text box
    > strDel= document.myform.elements(x).name +
    > document.myform.elements(x).id //set variable to the element with it's
    > id
    > if strDel <> " " then //if the element with this id isn't blank
    > insert these fields into the database
    > sqlD="INSERT INTO EstDelDate (EnteredBy, PO_PT, Line, FormDate,Part#,
    > EntryDate, EstDeliveryDate) VALUES ('" & strEmpName & "',
    > '" & strPurchase & "', '" & strLine & "', '" & strPDate & "', '"
    > & strPartNo & "', '" & Date() & "', '" & strDel & "')"
    > // strEmpName is user login
    > strPurchase-strPartNo are variables set to the fields taken from
    > the first database
    > Date() date function
    > strDel is my input variable
    > end if
    > end if
    > next
    > Cm2.Execute(sqlD)
    > end if
    > This is what my form kinda looks like:
    >
    > do until rs3.eof
    > strPurchase = rs3("PURCHASE ORDER NUMBER")
    > strLine = rs3("LINE NUMBER")
    > strPDate= rs3("PURCHASE DATE")
    >
    > // declare variables
    > %>
    > <tr%>
    > <td ><%=rs3("PURCHASE ORDER NUMBER")%></td>
    > <td "><%=rs3("LINE NUMBER")%></td>
    > <td ><%=rs3("PURCHASE DATE")%></td>
    > <td><input type="text" size=10 name="estDel"></td>
    > </tr>
    > <%
    > rs3.movenext
    > loop

    Ray at Guest

  4. #3

    Default Re: Getting the ID of an element to check existence and pass variables.

    Pull the record's primary key in to your recordset too and then you'll have
    the identifier, i.e.

    Ray at home

    "Renie83" <renie83@lycos.com> wrote in message
    news:8e153bdf.0307150442.3d82c665@posting.google.c om...
    > That is kinda what I want but I can't go through and assign each row
    > it's own hidden id tag because the input boxes and rows are just being
    > pulled into the asp page by using the move next of the recordset. Is
    > there some way in VBScript I can refer to their ordinal number?
    >
    >
    >
    > "Ray at <%=sLocation%>" <ray@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
    message news:<u#iziwmSDHA.1576@TK2MSFTNGP12.phx.gbl>...
    > > Hi Renie83,
    > >
    > > You're mixing up server-side code and client-side code. Request.Form is
    > > server side, but document.myform.elements.length is client-side. An ASP
    > > page will no idea what a document is, or what myform is. I suggest
    > > something like this:
    > >
    > > <FORM method="post" action="somepage.asp">
    > > <INPUT name="cmdSubmit" type="submit" />
    > > <TABLE>
    > > <TR>
    > > <TD>
    > > <INPUT name="txtSomething1" type="text" />
    > > <INPUT name="txtDate1" type="text" />
    > > <INPUT name="hidID" type="hidden" value="1" />
    > > </TD>
    > > </TR>
    > >
    > > <TR>
    > > <TD>
    > > <INPUT name="txtSomething2" type="text" />
    > > <INPUT name="txtDate2" type="text" />
    > > <INPUT name="hidID" type="hidden" value="2" />
    > > </TD>
    > > </TR>
    > >
    > > <TR>
    > > <TD>
    > > <INPUT name="txtSomething3" type="text" />
    > > <INPUT name="txtDate3" type="text" />
    > > <INPUT name="hidID" type="hidden" value="3" />
    > > </TD>
    > > </TR>
    > > </TABLE>
    > > <INPUT name="cmdSubmit" type="submit" />
    > > </FORM>
    > >
    > >
    > >
    > >
    > > Then, on your page that processes this, if I understand right, you want
    to
    > > process values only if the date textbox was filled in, do something
    like:
    > >
    > > Dim aIDs, iCounter, sSQL, sSomething
    > > aIDs = Split(Request.Form("hidID"), ", ")
    > > For iCounter = 0 To UBound(aIDs)
    > > sSomething = Request.Form("txtSomething" & aIDs(iCounter))
    > > If Request.Form("txtDate" & aIDs(iCounter)) <> "" Then ''date was
    > > entered
    > > sSQL = "INSERT INTO [TheTable] ([Something]) VALUES ('" &
    sSomething
    > > & "');"
    > > Cm2.Execute sSQL
    > > End If
    > > Next
    > >
    > >
    > > Ray at home
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > > "Renie83" <renie83@lycos.com> wrote in message
    > > news:8e153bdf.0307141412.12deffb0@posting.google.c om...
    > > > Thanks for the tips Ray!
    > > > Okay I think I can explain better now.
    > > > What my asp page displays are some records from a database table and a
    > > > text box after each record where a user can enter a date. I would like
    > > > to be able to check if a date is entered and if so, send that line of
    > > > information to a new database table where the information will be
    > > > stored. I've read about how VBScript applys an element id to each
    > > > element in a form. And I would like to know if I can use that id to
    > > > call on these elements. Any help would be greatly appreciated and I
    > > > hope I've explained it well.
    > > > Renie83
    > > >
    > > > I'm trying something like this:
    > > >
    > > > if request.form("submitTop") <> "" or request.form("submitBottom")<>
    > > > "" then
    > > > // Two submit buttons can be clicked and as long as the user has not
    > > > tried to submit a blank form do this
    > > > Dim x
    > > > for x= 0 to document.myform.elements.length-1 // get the number of
    > > > elements in the form
    > > > if left(document.myform.elements(x).name,3) ="txt" then //
    > > > check to see if it's a text box
    > > > strDel= document.myform.elements(x).name +
    > > > document.myform.elements(x).id //set variable to the element with it's
    > > > id
    > > > if strDel <> " " then //if the element with this id isn't blank
    > > > insert these fields into the database
    > > > sqlD="INSERT INTO EstDelDate (EnteredBy, PO_PT, Line, FormDate,Part#,
    > > > EntryDate, EstDeliveryDate) VALUES ('" & strEmpName & "',
    > > > '" & strPurchase & "', '" & strLine & "', '" & strPDate & "', '"
    > > > & strPartNo & "', '" & Date() & "', '" & strDel & "')"
    > > > // strEmpName is user login
    > > > strPurchase-strPartNo are variables set to the fields taken from
    > > > the first database
    > > > Date() date function
    > > > strDel is my input variable
    > > > end if
    > > > end if
    > > > next
    > > > Cm2.Execute(sqlD)
    > > > end if
    > > > This is what my form kinda looks like:
    > > >
    > > > do until rs3.eof
    > > > strPurchase = rs3("PURCHASE ORDER NUMBER")
    > > > strLine = rs3("LINE NUMBER")
    > > > strPDate= rs3("PURCHASE DATE")
    > > >
    > > > // declare variables
    > > > %>
    > > > <tr%>
    > > > <td ><%=rs3("PURCHASE ORDER NUMBER")%></td>
    > > > <td "><%=rs3("LINE NUMBER")%></td>
    > > > <td ><%=rs3("PURCHASE DATE")%></td>
    > > > <td><input type="text" size=10 name="estDel"></td>
    > > > </tr>
    > > > <%
    > > > rs3.movenext
    > > > loop

    Ray at Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139