Impact of giving same name to multiple text fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandhseke
    New Member
    • Jun 2009
    • 92

    #1

    Impact of giving same name to multiple text fields

    Hi Team,

    Could you please educate me with an explanation - What is the impact of giving same name for different text fields in HTML/ASP. I use JavaScript for Client side validation and few other functionalities , VB script for DB connection and Insert/Update operation to DB.

    Thanks for your help in advance.

    Regards,
    Chandhseke
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    say you have a form that looks like this:
    Code:
    <form action="response.asp" method="post">
    <input type="text" name="text1" value="mamba">
    <input type="text" name="text2" value="samba">
    <input type="submit" name="submit" value=submit>
    </form>
    and if response.asp had a very simple function that listed the form outputs, this is what you might see:
    Code:
    text1: mamba
    text2: samba
    submit: submit
    now if both text inputs were named "text1" then this would be the result:
    Code:
    text1: mamba,samba
    submit: submit
    Does this answer your question?

    Jared

    Comment

    • chandhseke
      New Member
      • Jun 2009
      • 92

      #3
      Hi Jared,
      Thanks for your response. Your example is correct but what if i have a scenario where we had submited a form and all form values is inserted to database using Insert query. Now i have a form with DB values <%=text1%>.

      Code:
      <form action="response.asp" method="post"> 
      If <%Variable = "Value" then%>
      <input type="text" name="text1" value="mamba"> 
      <%Else%>
      <input type="text" name="text1" value="mamba" disabled> 
      <%End If%>
      <input type="submit" name="submit" value=submit> 
      </form>
      Upon submission an Update query will update values based on If condition.. I am facing issues that during update all form data will be disappeared.

      How does this impact?Please advise.

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        You are not very clear on your question, so I am having a hard time understanding exactly what you want.

        First, Why do you have a lot of fields with the same name? My first impression is that this is bad practice, but I admit there are times when it would make sense.

        Second, if one of your inputs is disabled (as in your code) that value will not be sent when the form is submitted.

        Third, when you send multiple values in multiple inputs with the same name, they are not sent to the server as different values, they are sent to the server as a single comma-separated string. So if you have three text inputs with name "text1" and value "mamba" they ARE NOT SENT TO THE SERVER AS
        Code:
        text1="mamba"
        they are sent to the server as
        Code:
        text1="mamba,mamba,mamba"
        if you insert this into a db, and then search where textfield1="mam ba" you will get no records returned because the record you just inserted says textfield1="mam ba,mamba,mamba" .

        Fourth- I see several possibilities where your data might "disappear" . Without giving me more information, it would be hard for me to guess where it is disappearing. My first guess is the scenario I alluded to in the above paragraph.

        Jared

        Comment

        • chandhseke
          New Member
          • Jun 2009
          • 92

          #5
          Hi Jared,
          Sorry for confusion. I will give you a background of my scenario, we have an web application using ASP, JavaScript and VB Script. Common users access this application to create a supplier record with us and a user will be allowed to select 3 approvers to whom the request will be sent for approval in a sequential order. once they fill in all the fields and submit the form an email notification will be sent to approver 1 with form details(here the form is readonly and can oly approve/reject), upon approver one's apporval the same form be will sent to approver 2(here approver 2 can edit the details entered by user) and then to approver 3 etc.

          Since only approver 2 should be able edit the form we have used readonly feature for other approvers. I had used a variable to increment the form to each approvers so If a variable = 2 then we give an option to edit all fields in the form, upon submision an update query will be executed hence updating all fields. At this point, the data is dissapeared/updated with blank since as you said all fields are disabled and no data is passed to update query.

          Can you please edit the below code and advise how best i can code this so that all my data is safe.

          Code:
          <form action="MGRSQL_Update.asp?mode=Approve&var=<%=var%>&FormID=<%=Rec_IDQuery%>" method="post"  name="form1">
          
          <%If VAR = 2 then %>
                            <input id="Contact_Name" style="width: 225px" type="text" name="Contact_Name" value="<%=RsEdit("Contact_Name")%>"/>
                            <%Else %>
                            <input id="Contact_Name" style="width: 225px" type="text" name="Contact_Name" value="<%=RsEdit("Contact_Name")%>" disabled/>
                            <%End if %>
          
           <%If VAR = 2 then %>
                            <input id="Req_Email" style="width: 262px" type="text" name="Req_Email" value="<%=RsEdit("Req_Email")%>"/>
                            <%Else %>
                            <input id="Req_Email" style="width: 262px" type="text" name="Req_Email" value="<%=RsEdit("Req_Email")%>" disabled/>
                             <%End If %>
          </td>
           <%If VAR = 2 then %>
                            <input id="Req_Name" style="width: 225px" type="text" name="Req_Name" value="<%=RsEdit("Req_Name")%>"/>
                            <%Else %>
                            <input id="Req_Name" style="width: 225px" type="text" name="Req_Name" value="<%=RsEdit("Req_Name")%>" disabled/>
                            <%End If %>      
                            </td>
          
          <td><input id="Approve" style="width: 180px" type="submit" value="Approve"/></td>
          </form>
          Code:
          If VAR = 2 then
          	SQLUpdateDate = "Update Test set x="y", Z="a"------------------------------------------------------------, A="B""
          Else
          	SQLUpdateDate =	"Update Test set x="y", Z="a""
          End If
          
          oConn.Execute(SQLUpdateDate)

          Please let me know if you need more information regarding the functionality of the application.. Thanks in advance..

          Regards,
          Chandhseke

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            OK, it sounds to me that your problem is that the fields are disabled. If you know enough javascript, you can add a function that enables the inputs right before submitting the form, but I'm not really a javascript expert, so I'm not going to help you with that. The other option is to have a hidden input with the same name and value as the disabled text input. the data is sent, the user can't edit it. does this answer your question?

            Jared

            Comment

            • chandhseke
              New Member
              • Jun 2009
              • 92

              #7
              Thanks for your response.
              Code:
              <%If VAR = 2 then %> 
                                <input id="Req_Name" style="width: 225px" type="text" name="Req_Name" value="<%=RsEdit("Req_Name")%>"/> 
                                <%Else %> 
                                <input id="Req_Name" style="width: 225px" type="Hidden" name="Req_Name" value="<%=RsEdit("Req_Name")%>" disabled/> 
                                <%End If %>       
                                </td>
              Do you mean to say making the second input tag in <%Else%> to be of type hidden? Or introducing a new hidden text box. Can you please edit my above code.

              Regrds,
              Chandseke

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                either way should work. If they don't need to see the field, go ahead and change the type to "hidden". If you want them to see the field and understand that it is uneditable, then add a second field with type=hidden.

                I'm not interested in editing your code.

                Jared

                Comment

                • chandhseke
                  New Member
                  • Jun 2009
                  • 92

                  #9
                  Code:
                  <form action="MGRSQL_Update.asp?mode=Approve&var=<%=var%>&FormID=<%=Rec_IDQuery%>" method="post"  name="form1"> 
                    
                                    <input id="Contact_Name" style="width: 225px" type="text" name="Contact_Name" value="<%=RsEdit("Contact_Name")%>" <%If VAR <> 2 then %>Disabled<%Else %><%End If %>
                  /> 
                   <input id="Req_Email" style="width: 262px" type="text" name="Req_Email" value="<%=RsEdit("Req_Email")%>" <%If VAR <> 2 then %>Disabled<%Else %><%End If %>/> 
                  </td> 
                                    <input id="Req_Name" style="width: 225px" type="text" name="Req_Name" value="<%=RsEdit("Req_Name")%>" <%If VAR <> 2 then %>Disabled<%Else %><%End If %>/> 
                                              </td> 
                    
                  <td><input id="Approve" style="width: 180px" type="submit" value="Approve"/></td> 
                  </form>
                  Will this new code makes any difference compared to first code that i sent you as an example? Please advise

                  Comment

                  • jhardman
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3405

                    #10
                    yes, it makes a difference. Your code in reply 7 will create a hidden input that will post data. Your code in reply 9 will create a disabled textarea that will not post data.

                    Jared

                    Comment

                    • chandhseke
                      New Member
                      • Jun 2009
                      • 92

                      #11
                      Great, understood the difference but one small question. Does my code in reply 9 would solve the data loss issue anyway? While Var=2, will this send all data via an update query to DB. (I want my code to post data only when VAR = 2 is true else i am not updating all data feilds value rather i am just marking a separate column in database with current date to show it was approved on the particular day)Please advise.

                      Comment

                      • chandhseke
                        New Member
                        • Jun 2009
                        • 92

                        #12
                        Hi Jared,
                        I have come up with a new code to address my ongoing data loss issue, your advise above helped a lot to resolve the issue.please advise if this works fine, sorry for interupting you more.

                        Code:
                         <tr>
                                         <%If VAR = 2 then%> 
                                          <td colspan="4" class="BoldFont" style="width: 112px; height: 27px;">Scope <font color="red">*</font>
                                          <select name="Scope" style="width:250px" id="Scope">
                                              <option selected value="<%=RsEdit("Scope")%>"><%=RsEdit("Scope")%></option>
                                              <option value="IT-Hardware">IT-Hardware</option>
                                              <option value="IT-Software">IT-Software</option>
                                              <option value="Telecommunications">Telecommunications</option>
                                              <option value="Indirect">Indirect</option>
                                              <option value="Labor">Labor</option>
                                              <option value="Manufacturing">Manufacturing</option>
                                            </select>                   
                                          </td>
                                          <%Else %>
                                          <td><%=RsEdit("Scope")%></td>
                                          <%End if %>
                        </tr>
                        Please advise how does posting happen acoording to my new code. Thanks for all your help in advance!!

                        Regards,
                        CS

                        Comment

                        • jhardman
                          Recognized Expert Specialist
                          • Jan 2007
                          • 3405

                          #13
                          that should work just fine

                          Jared

                          Comment

                          • chandhseke
                            New Member
                            • Jun 2009
                            • 92

                            #14
                            Hi,
                            Thanks much i am using the above code now.. If i come across with any unresolvable issues i will contact you.

                            Thanks again!!

                            Regards,
                            Chandhseke

                            Comment

                            Working...