Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make a text field read only 1

Status
Not open for further replies.

jeellison

IS-IT--Management
May 29, 2002
78
GB
Good day all,

I have a login form and when the user logs in they are faced with a ticket system for addinng new jobs. SO I have a Job_ID in a text field which increments each time a new one is added but how do I make this read only so it cannot be changed?

I have the following

<input name="job_number" type="int" id="job_number" value="<%=(Recordset2.Fields.Item("ID").Value)%>" />

Thanks all
James
 
OR is there a way of passing just the text from a recordset back to the DB?

ie, it isnt in a text file to start with?

I hope ive made myself clear as im new to all this.

Thanks
James
 
type="int"

That isn't valid. Most browsers are 'forgiving' enough to allow the page to show, but INT is not a valid control type.

There are a couple of ways to handle this. If you want the user to see the job id, then, by all means, put it in a text box. Like this...

Code:
<input name="job_number" type="[!]Text[/!]" [!]disabled="disabled"[/!] id="job_number" value="<%=(Recordset2.Fields.Item("ID").Value)%>" />

If it's not important (or desireable) for the user to see the job_id, then simply put it in a hidden control. Like this...

Code:
<input name="job_number" id="job_number" type="[!]hidden[/!]" value="<%=(Recordset2.Fields.Item("ID").Value)%>" />

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi George,

This is exactly what I need BUT now it does not write it to the DB when submitted. The user does need to see the ID which is the primary key.

Any ideas why?

Thanks
James
 
No idea. The problem must be elsewhere. I would encourage you to show the part of code where you are using these values.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I think its just this bit you need:

Code:
<%
If (CStr(Request("MM_insert")) = "form2") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_tynans_mysql_STRING
    MM_editCmd.CommandText = "INSERT INTO tynansdb.tynan_jobs (job_number, job_date, customer_name, customer_ref, site, contact_name, contact_number, job_details, engineer_name, created_by, job_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" 
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("job_number"), Request.Form("job_number"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 135, 1, -1, MM_IIF(Request.Form("job_date"), Request.Form("job_date"), null)) ' adDBTimeStamp
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 255, Request.Form("customer_name")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, 255, Request.Form("customer_ref")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, 255, Request.Form("site")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 201, 1, 255, Request.Form("contact_name")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("contact_number"), Request.Form("contact_number"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 201, 1, 255, Request.Form("job_details")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 201, 1, 255, Request.Form("engineer_name")) ' adLongVarChar
	MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 201, 1, 255, Request.Form("created_by")) ' adLongVarChar
	MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 201, 1, 255, Request.Form("job_status")) ' adLongVarChar
	
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "create_a_new_job.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>



<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
  <tr>
    <td width="1000" height="707" valign="top"><table width="1000" height="25" border="0" cellpadding="0" cellspacing="0" class="header">
      <tr>
        <td height="25" valign="top"><table width="1000" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="80" height="25">&nbsp;</td>
              <td width="606">&nbsp;</td>
              <td width="142" class="site_text style3">Tel : 00 44 1942 322950</td>
              <td width="172" class="site_text style3">E-mail : Info@tynans.co.uk</td>
            </tr>
            <tr>
              <td height="25">&nbsp;</td>
              <td>&nbsp;</td>
              <td colspan="2" rowspan="2" class="site_text style3"><label>
                <input type="text" name="Search" id="Search" />
                </label>
                  <label>
                  <input name="Search2" type="submit" class="site_text" id="Search2" value="Search" />
                </label></td>
            </tr>
            <tr>
              <td height="25">&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td height="25">&nbsp;</td>
              <td colspan="2" valign="top"><span class="site_text">
                </span>
                <form id="form1" name="form1" method="link" action="[URL unfurl="true"]http://www.tynans.jglobal.co.uk/create_a_new_job.asp">[/URL]
                  <span class="site_text"><a href="create_a_new_job.asp">New Job</a>&nbsp; |&nbsp;<a href="view_all_jobs.asp">View all Jobs</a>&nbsp;</span> <span class="site_text">|&nbsp;&nbsp;<a href="edit_jobs.asp">Edit Jobs</a></span> <span class="site_text">|&nbsp;&nbsp;<a href="delete_a_job.asp">Delete a Job</a></span> <span class="site_text">|</span> <span class="site_text"><a href="my_jobs.asp">View My Jobs</a></span> | <span class="site_text"><a href="open_jobs.asp">View Open Jobs</a> | <a href="closed_jobs.asp">View Closed Jobs</a>                  </span>
                </form>                </td>
              <td valign="top" class="site_text style3"><a href="<%= MM_Logout %>">Log Out</a></td>
            </tr>
        </table></td>
      </tr>
    </table>
    <table width="1000" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="1000" height="534" valign="top" class="main_image_1"><table width="1000" height="628" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="20" colspan="3" valign="top"><img src="file:///S|/B&amp;Q/Projects/websites/tynans.co.uk/spacer.gif" width="1" height="1" /></td>
            </tr>
            <tr>
              <td width="15" height="518" valign="top" bgcolor="#2D333F">&nbsp;</td>
              <td width="900" height="518" valign="top" class="black_menu1"><p><span class="black_menu_header">Create a new Job.</span><br />
                </p>
                  <table width="928" height="421" border="0" align="right" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="30" height="421" valign="top">&nbsp;</td>
                      <td class="solutions_border"><form ACTION="<%=MM_editAction%>" METHOD="POST" id="form2" name="form2">
                        <table width="601" height="340" border="1" align="center" bordercolor="#464646">
                          <tr>
                            <td width="135" height="28">Job Number</td>
                            <td width="404"><label>
                              <input name="job_number" type="text" disabled="disabled" id="job_number" value="<%=(Recordset2.Fields.Item("ID").Value)%>" />
                            </label></td>
                            <td width="40">&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Date :</td>
                            <td><label>
                            <input name="job_date" type="text" id="job_date" />
                            &nbsp;&nbsp;&nbsp;eg 21/03/2008</label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Customer : </td>
                            <td><label>
                              <select name="customer_name" id="customer_name">
                                <option value="B&Q" <%If (Not isNull((Recordset1.Fields.Item("customer_name").Value))) Then If ("B&Q" = CStr((Recordset1.Fields.Item("customer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>B&Q</option>
                                <option value="Screw-Fix" <%If (Not isNull((Recordset1.Fields.Item("customer_name").Value))) Then If ("Screw-Fix" = CStr((Recordset1.Fields.Item("customer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Screw-Fix</option>
                              </select>
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td height="26">Customer Reference : </td>
                            <td><label>
                              <input name="customer_ref" type="text" id="customer_ref" />
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Site : </td>
                            <td><label>
                              <input name="site" type="text" id="site" />
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Contact Name :</td>
                            <td><label>
                              <input name="contact_name" type="text" id="contact_name" />
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Contact Number : </td>
                            <td><label>
                              <input name="contact_number" type="text" id="contact_number" />
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Job Details : </td>
                            <td><label>
                              <textarea name="job_details" id="job_details" cols="45" rows="5"></textarea>
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Assign to : </td>
                            <td><label>
                              <select name="engineer_name" id="engineer_name">
                                <option value="Un-assigned" <%If (Not isNull((Recordset1.Fields.Item("engineer_name").Value))) Then If ("Un-assigned" = CStr((Recordset1.Fields.Item("engineer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Un-assigned</option>
                                <option value="Neil Kenny" <%If (Not isNull((Recordset1.Fields.Item("engineer_name").Value))) Then If ("Neil Kenny" = CStr((Recordset1.Fields.Item("engineer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Neil Kenny</option>
                                <option value="Brad Beckett" <%If (Not isNull((Recordset1.Fields.Item("engineer_name").Value))) Then If ("Brad Beckett" = CStr((Recordset1.Fields.Item("engineer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Brad Beckett</option>
                                <option value="Wayne Johnson" <%If (Not isNull((Recordset1.Fields.Item("engineer_name").Value))) Then If ("Wayne Johnson" = CStr((Recordset1.Fields.Item("engineer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Wayne Johnson</option>
                                <option value="Paul Kirton" <%If (Not isNull((Recordset1.Fields.Item("engineer_name").Value))) Then If ("Paul Kirton" = CStr((Recordset1.Fields.Item("engineer_name").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Paul Kirton</option>
                              </select>
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Created by</td>
                            <td><label>
                            <input type="text" disabled="disabled" name="created_by" id="created_by" value= <%= session("varuser")%> />
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>Job Status</td>
                            <td><label>
                              <select name="job_status" id="job_status">
                                <option value="Open" <%If (Not isNull((Recordset1.Fields.Item("job_status").Value))) Then If ("Open" = CStr((Recordset1.Fields.Item("job_status").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Open</option>
                                <option value="Closed" <%If (Not isNull((Recordset1.Fields.Item("job_status").Value))) Then If ("Closed" = CStr((Recordset1.Fields.Item("job_status").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Closed</option>
                              </select>
                            </label></td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><input type="submit" name="Save" id="Save" value="Submit" /></td>
                            <td>&nbsp;</td>
                          </tr>
                        </table>
                                            
                        
                        
                      
                        
                        
                        <input type="hidden" name="MM_insert" value="form2" />
                      </form>                      </td>
                    </tr>
                </table></td>
              <td width="15" height="518" valign="bottom" bgcolor="#0D0D0D">&nbsp;</td>
            </tr>
            <tr>
              <td height="23" colspan="3" background="file:///S|/B&amp;Q/Projects/websites/tynans.co.uk/images/gradient_solutions_page.gif">&nbsp;</td>
            </tr>
            <tr>
              <td height="23" colspan="3" background="file:///S|/B&amp;Q/Projects/websites/tynans.co.uk/images/gradient_solutions_page.gif">&nbsp;</td>
            </tr>
            <tr>
              <td height="19" colspan="3" valign="middle" background="file:///S|/B&amp;Q/Projects/websites/tynans.co.uk/images/gradient_solutions_page.gif"><div align="center"><span class="site_text style4">Home | Company | Services | Case Studies | Contact Us  | Site Map | Online Privacy Policy | Terms of Use | Accessibility |  Send Feedback<img src="file:///S|/B&amp;Q/Projects/websites/tynans.co.uk/spacer.gif" alt="" width="1" height="1" /></span></div></td>
            </tr>
          </table></td>
        </tr>
      </table>
    </td>
  </tr>
</table>

<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td class="site_text"><div align="center">Copyright © 2008 Tynan Elecrical Limited. All rights reserved</div></td>
  </tr>
</table>
</body>

Any help will be great.

James
 
Basically I have :

<%
If (CStr(Request("MM_insert")) = "form2") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_tynans_mysql_STRING
MM_editCmd.CommandText = "INSERT INTO tynansdb.tynan_jobs (job_number, job_date, customer_name, customer_ref, site, contact_name, contact_number, job_details, engineer_name, created_by, job_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("job_number"), Request.Form("job_number"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 135, 1, -1, MM_IIF(Request.Form("job_date"), Request.Form("job_date"), null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 255, Request.Form("customer_name")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, 255, Request.Form("customer_ref")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, 255, Request.Form("site")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 201, 1, 255, Request.Form("contact_name")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("contact_number"), Request.Form("contact_number"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 201, 1, 255, Request.Form("job_details")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 201, 1, 255, Request.Form("engineer_name")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 201, 1, 255, Request.Form("created_by")) ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 201, 1, 255, Request.Form("job_status")) ' adLongVarChar

MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "create_a_new_job.asp"
If (Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>



<input name="job_number" type="text" id="job_number" value="<%=(Recordset1.Fields.Item("ID").Value)%>" />

This works and adds it to the DB but if I put in the disabled="disabled" it doesnt write it to the db.

Thanks
James
 
I would suggest that you use the HIDDEN type. If you want the user to see the number, then you can also display it.

Something like...

Code:
<input name="job_number" id="job_number" type="hidden" value="<%=(Recordset2.Fields.Item("ID").Value)%>" />
JobNumber: <%=(Recordset2.Fields.Item("ID").Value)%>

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Alternatively, could one pull the job number value, throw it to a session variable, display it on the form as uneditable text, and then populate the database upon form submission with a mix of the request.form items and session variable(s)?

 
Hi George,

That works perfectly now.

Thanks so much.
James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top