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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disabling fields 1

Status
Not open for further replies.

jeellison

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

Here we go again!

I have a page which displays all the data from a sql record. It is only viewable to engineers who are assigned to it (there is a primary and secondary engineers) So now both engineers can view the same record but I dont want them to be able to change each others notes.

There is a primary engineer text field for his notes and a secondary engineer field for his notes. Is there a way of disabling the primary engineers notes field if the secondary engineers is viewing and vice versa?

Im using a session variable for logged in engineers.

I hope I make sence?

Thanks in advance
James
 
I would think yes.

If you using a login variable and can tell who is looking at the page (say it is the 2ndary eng) then you should be able to diplay the 2ndary notes as a prepopulated text field that can be edited and submitted to update, while just displaying the primary engineers notes as text.

Does your table look like?
tblprojects: project_num, bunch_of_data_fields, primary_eng, prim_eng_notes, secondary_eng, secondary_eng_notes, other_fields

Could I be a primary on one project and the secondary on another (or vice versa)?

I think you would
Load the recordset: select * from tblprojects where project_num equals targeted project number

Write the data to a mix of form and text:
if session_login_name variable equals rs("primary_eng")
response.write an input form box prepopulated with rs("prim_eng_notes")
else
response.write rs("prim_eng_notes") as some text
and
if session_login_name variable equals rs("secondary_eng")
response.write an input form box prepopulated with rs("secondary_eng_notes")
else
response.write rs("secondary_eng_notes") as some text

Action on the form updates the database to capture changes.

 
Ah BigRed you again.

Thanks so much, this is exactly what I wanted instead of loads of fields on my age which I have at the moment as their is a tertiary engineer too.

Just need to figure out the code on how to implement this now.


Thanks
James
 
Hello Again,

Ive tried to implement this but I'm obviously just writing rubbish. Is their any help files on this you know of on how to use the If statement.

Best Regards
James
 
So far I have this :

<%If (Recordset1.Fields.Item("engineer_name").Value) = session("varuser") Then %>
<textarea name="engineers_notes" id="engineers_notes" cols="40" rows="5">
<%Response.Write(Recordset1.Fields.Item("engineers_notes").Value)%>
</textarea>
<%else response.write("failed")
End if %>

And all I get is failed (not in a text box)

Any help would be great.

Thanks
James
 
String comparisons in ASP are case sensitive. Perhaps that is your problem?

Code:
<%If [!]UCase[/!](Recordset1.Fields.Item("engineer_name").Value) = [!]UCase([/!]session("varuser")[!])[/!] Then %>

-George

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

No im getting the same result with this :

<%If UCase(Recordset1.Fields.Item("engineer_name").Value) = UCase(session("varuser")) Then %>
<textarea name="engineers_notes" id="engineers_notes" cols="40" rows="5">
<%=Response.Write(Recordset1.Fields.Item("engineers_notes").Value)%>
</textarea>
<%else response.write("failed")
End if %>

Thanks
James
 
George - You are a legend thanks.

James
 
One little problem I have just run into.

Now that I have the IF statement working so that it just displays the 'other' engineers data as text and their own as a text field. When you click submit it overwrites nothing to the db (but only for the text on its own)

Any ideas.

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

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_tynans_mysql_STRING
MM_editCmd.CommandText = "UPDATE tynansdb.tynan_jobs SET engineers_notes = ?, materials = ?, time_on_site = ?, time_off_site = ?, total_on_site = ?, travel_time = ?, total_hours = ?, secondary_engineers_notes = ? WHERE ID = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 16777215, Request.Form("engineers_notes")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 16777215, Request.Form("materials")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 500, Request.Form("time_on_site")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202, 1, 500, Request.Form("time_off_site")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 5, 1, -1, MM_IIF(Request.Form("total_on_site"), Request.Form("total_on_site"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("travel_time"), Request.Form("travel_time"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("total_hours"), Request.Form("total_hours"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 202, 1, 16777215, Request.Form("secondary_engineers_notes")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble

MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "my_jobs.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
%>

Must be because their is no Request.Form("engineers_notes") or Request.Form("secondary_engineers_notes") if it is only displayed as text but Im not sure of how to work around this.

Best Regards
James
 
Or is it here?

<%If UCase(Recordset1.Fields.Item("second_engineer").Value) = UCase(session("varuser")) Then %>
<textarea name="secondary_engineers_notes" id="secondary_engineers_notes" cols="40" rows="5" value><%=(Recordset1.Fields.Item("secondary_engineers_notes").Value)%></textarea>
<%else Response.Write(Recordset1.Fields.Item("secondary_engineers_notes").Value)
End if %>
 
You could try using a hidden input field, which will show up in the request object, but won't be seen on your page.

Code:
<% If UCase(Recordset1.Fields.Item("second_engineer").Value) = UCase(session("varuser")) Then %>
	<textarea name="secondary_engineers_notes" id="secondary_engineers_notes" cols="40" rows="5" value><%=(Recordset1.Fields.Item("secondary_engineers_notes").Value)%></textarea>
<% Else%>
    <input type="hidden" name="secondary_engineers_notes" id="secondary_engineers_notes" value="<% =Recordset1.Fields.Item("secondary_engineers_notes").Value %>" /><% =Recordset1.Fields.Item("secondary_engineers_notes").Value %>
<% End if %>

That code looks ugly, so.... basically, you use a hidden form element to store the value AND also display the value (because that's what you were already doing).

Make sense?

-George

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

YES, that is what ive been trying to do but it still doesnt seem to work. Your code does not write the data as text when the else is executed- It is just blank.

im using

<% If UCase(Recordset1.Fields.Item("engineer_name").Value) = UCase(session("varuser")) Then %>
<textarea name="engineers_notes" id="engineers_notes" cols="40" rows="5" value><%=(Recordset1.Fields.Item("engineers_notes").Value)%></textarea>
<%Else%>
<input type="hidden" name="engineers_notes" id="engineers_notes" value="<%=Recordset1.Fields.Item("engineers_notes").Value%>"/><%Response.Write(Recordset1.Fields.Item("engineers_notes").Value)%>
<% End if %>

Is it this that is Ugly?

Thanks
James
 
The reason I said 'ugly' is because I like to demonstrate code that (I think) is easy to understand. In this case, the lines are long with lot's of markup embedded, so it's not as easy to understand (and therefore ugly).

That being said.... this absolutely should work. I see no reason why it wouldn't.

If you view the source for the page, do you see the engineers_notes in the hidden form element?

I suppose you could try setting the value to a local variable and then use it in the page, like this...

Code:
<% 
   EngineersNotes = Recordset1.Fields.Item("engineers_notes").Value
   If UCase(Recordset1.Fields.Item("engineer_name").Value) = UCase(session("varuser")) Then %>
    <textarea name="engineers_notes" id="Textarea1" cols="40" rows="5"><%=EngineersNotes%></textarea>
<% Else%>
    <input type="hidden" name="engineers_notes" id="Hidden1" value="<%=EngineersNotes%>"/><%=EngineersNotes%>
<% End if %>

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
It all seems to work apart from the actual writing of the text on its own now. If I take out the type="hidden" then it all works apart from then it is in a text field.

Must be something simple.

Thanks
James
 
Try wrapping it in a <p> element.

Code:
<% 
   EngineersNotes = Recordset1.Fields.Item("engineers_notes").Value
   If UCase(Recordset1.Fields.Item("engineer_name").Value) = UCase(session("varuser")) Then %>
    <textarea name="engineers_notes" id="Textarea1" cols="40" rows="5"><%=EngineersNotes%></textarea>
<% Else%>
    <input type="hidden" name="engineers_notes" id="Hidden1" value="<%=EngineersNotes%>"/>[!]<p>[/!]<%=EngineersNotes%>[!]</p>[/!]
<% End if %>

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Sweet As george.

I posted without seeing your new variable answer and it works great without the <p> element.

Again thank you soo much.

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top