...

View Full Version : disable text box



priyapratheep
05-24-2009, 07:28 PM
Hi friends

I want to disable my text box using java script.

Here "a" is the line number where change dynamically

var remarks="remarks"+a
var remarks_1=document.getElementById(remarks)

document.f_update.remarks_1.disabled== "true";

f_update is the form name.

It is not working..Pls help

thanks in advance

Old Pedant
05-24-2009, 08:04 PM
You put in too much code.


var remarks="remarks"+a;
var remarks_1=document.getElementById(remarks);
remarks_1.disabled = true;

Or, more compactly:


document.getElementById("remarks" + a).disabled = true;


This assumes that you have a field that has an ID (not a name!) of "remarksXXX" where "XXX" is whatever is in the variable a or your post.

If you can't make it work, show more code. Including the <FORM> and including where you assign a value to the varible a.

priyapratheep
05-24-2009, 08:26 PM
Thanks for the quick reply

I tried both.Not working

The line where i use is


<form method="get" action="sap_req_form_p.jsp" name="f_update">


<td><input type="text" size = "14" name="remarks" /></td>


The whole code is


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" import="java.io.*,java.text.*,java.sql.*,java.util.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAP REQ Form</title>
<LINK REL=stylesheet HREF="ssl.css" TYPE="text/css">
<style type="text/css">
<!--
body {
margin-left: 20px;
margin-top: 20px;
}
-->
</style>
<script type="text/JavaScript"><!--
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

// -->
</script>
<script type="text/JavaScript">
function update_query(a)
{
var req_no="req_no"+a
var req_no_1=document.getElementById(req_no)
var desc="desc"+a
var desc_1=document.getElementById(desc)
var WB_CUS="WB_CUS"+a
var WB_CUS_1=document.getElementById(WB_CUS)
var req_date="req_date"+a
var req_date_1=document.getElementById(req_date)
var req_by="req_by"+a
var req_by_1=document.getElementById(req_by)
var souce="souce"+a
var souce_1=document.getElementById(souce)
var TC_070="TC_070"+a
var TC_070_1=document.getElementById(TC_070)
var TC_071="TC_071"+a
var TC_071_1=document.getElementById(TC_071)
var TC_080="TC_080"+a
var TC_080_1=document.getElementById(TC_080)
var TC_170="TC_170"+a
var TC_170_1=document.getElementById(TC_170)
var TC_171="TC_171"+a
var TC_171_1=document.getElementById(TC_171)
var SNo="SNo"+a
var SNo_1=document.getElementById(SNo)
var remarks="remarks"+a
var remarks_1=document.getElementById(remarks)
//document.getElementById("remarks" + a).disabled = true;
//req_no_1.disabled = true;

var u="u";

if(TC_070_1.value=="cancel" || TC_071_1.value=="cancel" || TC_080_1.value=="cancel" || TC_171_1.value=="cancel")
{
alert("succ");
req_no.disabled="True";
req_no.readOnly="True";
desc.disabled="True";
req_no_1.disabled="True";
req_no_1.readOnly="True";
desc.disabled="True";
//document.f_update.req_no_1.disabled="true";
//document.f_update.req_no1.readOnly = true;
}

var myjsp2call = "sap_req_form_ver2.jsp?req_no="+req_no_1.value+"&flag="+u+"&descs="+desc_1.value+"&WB_CUS="+WB_CUS_1.value+"&req_date="+req_date_1.value+"&req_by="+req_by_1.value+"&souce="+souce_1.value+"&TC_070="+TC_070_1.value+"&TC_071="+TC_071_1.value+"&TC_080="+TC_080_1.value+"&TC_170="+TC_170_1.value+"&TC_171="+TC_171_1.value+"&SNo="+SNo_1.value+"&remarks="+remarks_1.value;
//alert(myjsp2call);
window.location.href = myjsp2call;


}

</script>

<script type="text/JavaScript">

function insert_query(a)
{
var t='a';

var myjsp2call = "sap_req_form_ver2.jsp?req_no="+document.f.req_no.value+"&flag="+t+"&descs="+document.f.desc.value+"&WB_CUS="+document.f.WB_CUS.value+"&req_date="+document.f.req_date.value+"&req_by="+document.f.req_by.value+"&souce="+document.f.souce.value+"&TC_070="+document.f.TC_070 .value+"&TC_071="+document.f.TC_071.value+"&TC_080="+document.f.TC_080.value+"&TC_170="+document.f.TC_170.value+"&TC_171="+document.f.TC_171.value+"&remarks="+document.f.remarks.value;
window.location.href = myjsp2call;

}

</script>

<style type="text/css">
body {
font-family: Helvetica;
font-size: 11px;
color: #000;
}

h3 {
margin: 0px;
padding: 0px;
}

.suggestionsBox {
position: relative;
left: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #3574EC7;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionsBox1 {
position: relative;
left: 200px;
margin: 20px 0px 0px 0px;
width: 700px;
background-color: #3574EC7;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}

.suggestionList {
margin: 0px;
padding: 0px;
}

.suggestionList li {

margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}

.suggestionList li:hover {
background-color: #659CD8;
}
</style>

</head>

<body>
<%!
Connection con;
Statement st;
ResultSet rs;
String req_no="";String descs="";String WB_CUS="";String req_date="";String req_by="";String souce="";String TC_070="";String TC_071="";String TC_080="";String TC_171="";String TC_170=""; String dmy ;
String SNo="";String temp_trans="";String remarks="";
%>
<%!public String getTableHeader(String width) {
String a = "";
StringBuffer sb = new StringBuffer();
sb.append("<table width=\"" + width + "\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#4682b4\">");
sb.append("<tr><td>");
sb.append("<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">");
return sb.toString();
}%>
<H1>
NEW Request
</H1>
<BR>


<div>
<table width="" border="0" cellpadding="1" cellspacing="0" bgcolor="#4682b4">
<tr>
<td>
<form method="get" action="" name="f">

<table width="100%" border="0" cellpadding="4" cellspacing="1">

<tr class="data2">
<th>Req No</th> <th>Desc</th> <th>WorkBench/<br>Customization</th> <th>Req Date</th> <th>Req By</th> <th>Source<br>Client</th><th colspan="5">Target Client</th><th>Remarks</th><th>Apply Change</th>

</tr>

<tr class="data2">
<th colspan="6">&nbsp;</th> <td>070</td>
<td>071</td><td>080</td><td>170</td>
<td>171</td><td></td><td></td>

</tr>
<%
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" ) ;
Calendar cal = Calendar.getInstance() ;
String dmy = sdf.format( cal.getTime() ) ;
cal.add( Calendar.DATE, -7 ) ;
String last = sdf.format( cal.getTime() ) ;
%>

<%
try
{
con = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://192.168.8.49/test?user=dbuser&password=xxxx");
st = con.createStatement();
String flags = request.getParameter("flag");
if (request.getParameter("flag") == null)
{}
else
{
out.println("hans"+request.getParameter("flag"));
if (request.getParameter("flag").equals("a"))
{


req_no=request.getParameter("req_no");
descs=request.getParameter("descs");
WB_CUS=request.getParameter("WB_CUS");
req_date=request.getParameter("req_date");
req_by=request.getParameter("req_by");
souce=request.getParameter("souce");
TC_070=request.getParameter("TC_070");
TC_071=request.getParameter("TC_071");
TC_080=request.getParameter("TC_080");
TC_170=request.getParameter("TC_170");

TC_171=request.getParameter("TC_171");

remarks=request.getParameter("remarks");


String Query="insert into test.SAP_REQ(req_no,descs,WB_CUS,req_date,req_by,source,client_070,client_071,client_080,client_170, client_171,remarks) values('"+req_no+"','"+descs+"','"+WB_CUS+"','"+req_date+"','"+req_by+"','"+souce+"','"+TC_070+"','"+TC_071+"','"+TC_080+"','"+TC_170+"','"+TC_171+"','"+remarks+"')";

int insert_flag=st.executeUpdate(Query);

Query="insert into test.SAP_REQ_LOG(req_no,descs,WB_CUS,req_date,req_by,source,client_070,client_071,client_080,client_ 170,client_171,remarks) values('"+req_no+"','"+descs+"','"+WB_CUS+"','"+req_date+"','"+req_by+"','"+souce+"','"+TC_070+"','"+TC_071+"','"+TC_080+"','"+TC_170+"','"+TC_171+"','"+remarks+"')";


insert_flag=st.executeUpdate(Query);
req_no="";
descs="";
WB_CUS="";
req_date="";
req_by="";
souce="";
TC_070="";
TC_071="";
TC_080="";
TC_170="";


TC_171="";

String redirectURL = "http://192.168.8.49/sap_req_form_ver2.jsp";
response.sendRedirect(redirectURL);
}
else
{
out.println("flag is false");
}

}
con.close();
}catch(Exception e)
{
out.println("Exception in connection : " + e.toString());
}
%>


<%
try
{
con = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://192.168.8.49/test?user=dbuser&password=xxxx");
st = con.createStatement();
String flags = request.getParameter("flag");
if (request.getParameter("flag") == null)
{}
else
{
out.println("hans"+request.getParameter("flag"));
if (request.getParameter("flag").equals("u"))
{

req_no=request.getParameter("req_no");
descs=request.getParameter("descs");
WB_CUS=request.getParameter("WB_CUS");
req_date=request.getParameter("req_date");
req_by=request.getParameter("req_by");
souce=request.getParameter("souce");
TC_070=request.getParameter("TC_070");
TC_071=request.getParameter("TC_071");
TC_080=request.getParameter("TC_080");
TC_170=request.getParameter("TC_170");

TC_171=request.getParameter("TC_171");
SNo=request.getParameter("SNo");
remarks=request.getParameter("remarks");
String Query ="UPDATE test.SAP_REQ SET req_no = '"+req_no+"' , descs = '"+descs+"',WB_CUS='"+WB_CUS+"',req_date='"+req_date+"',req_by='"+req_by+"',source='"+souce+"',client_070='"+TC_070+"',client_071='"+TC_071+"',client_080='"+TC_080+"',client_170='"+TC_170+"',client_171='"+TC_171+"',remarks='"+remarks+"' where SNo='"+SNo+"'";

int insert_flag=st.executeUpdate(Query);

String Query_insert="insert into test.SAP_REQ_LOG(req_no,descs,WB_CUS,req_date,req_by,source,client_070,client_071,client_080,client_ 170,client_171,remarks) values('"+req_no+"','"+descs+"','"+WB_CUS+"','"+req_date+"','"+req_by+"','"+souce+"','"+TC_070+"','"+TC_071+"','"+TC_080+"','"+TC_170+"','"+TC_171+"','"+remarks+"')";
int insert_flag1=st.executeUpdate(Query_insert);


req_no="";
descs="";
WB_CUS="";
req_date="";
req_by="";
souce="";
TC_070="";
TC_071="";
TC_080="";
TC_170="";


TC_171="";

String redirectURL = "http://192.168.8.49/sap_req_form_ver2.jsp";
response.sendRedirect(redirectURL);

);

}
else
{
out.println("flag is false");
}

}
con.close();


}catch(Exception e)
{
// con.close();
out.println("Exception in connection : " + e.toString());
}
%>























<tr class="data1">
<td><input type="text" size = "10" name="req_no" /></td><td><input type="text" size = "20" name="desc" /></td>
<td><select name="WB_CUS"><option value="WB">WB</option><option value="CUS">CUS</option></td>
<td><input type="text" size = "9" name="req_date" value=<%= dmy %> /></td>

<td><input type="text" size = "9" name="req_by" /></td>

<td><select name="souce" ><option value="060">060</option></td>

<td><select name="TC_070"><option value="NA">NA</option> <option value="Transport">Transport</option> </td>

<td><select name="TC_071"><option value="NA">NA</option> <option value="Transport">Transport</option> </td>

<td><select name="TC_080"><option value="NA">NA</option> <option value="Transport">Transport</option> </td>

<td><select name="TC_170"><option value="NA">NA</option> <option value="Transport">Transport</option> </td>

<td><select name="TC_171"><option value="NA">NA</option> <option value="Transport">Transport</option> </td>

<td><input type="text" size = "14" name="remarks" /></td>




<td>
<button type="button" OnClick ="insert_query(2);"/>Add</button>


</td>
</tr>
</table>
</table>

</form>
</div>



<H1>
Request History
</H1>
<BR>
<div>
<table width="" border="0" cellpadding="1" cellspacing="0" bgcolor="#4682b4">
<tr>
<td>
<form method="get" action="sap_req_form_p.jsp" name="f_update">

<table width="100%" border="0" cellpadding="4" cellspacing="1">


<tr class="data2">
<th>SNo</th><th>Req No</th> <th>Desc</th> <th>WorkBench/<br>Customization</th> <th>Req Date</th> <th>Req By</th> <th>Source<br>Client</th><th colspan="5">Target Client</th><th>Remarks</th><th>Apply Change</th>

</tr>

<tr class="data2">
<th colspan="7">&nbsp;</th> <td>070</td>
<td>071</td><td>080</td><td>170</td>
<td>171</td><td></td><td></td>







</tr>
<%
SimpleDateFormat sdf1 = new SimpleDateFormat( "yyyy-MM-dd" ) ;
Calendar cal1 = Calendar.getInstance() ;
String dmy1 = sdf1.format( cal1.getTime() ) ;
cal1.add( Calendar.DATE, -7 ) ;
String last1 = sdf1.format( cal1.getTime() ) ;
%>


<%
try
{
con = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://192.168.8.49/test?user=dbuser&password=xxxxx");
st = con.createStatement();
rs=st.executeQuery("select * from SAP_REQ order by SNo");
String flags = request.getParameter("flag");
while (rs.next())
{

SNo=rs.getString("SNo");
req_no=rs.getString("req_no");
descs=rs.getString("descs");
WB_CUS=rs.getString("WB_CUS");
req_date=rs.getString("req_date");
req_by=rs.getString("req_by");
souce=rs.getString("source");
TC_070=rs.getString("client_070");
TC_071=rs.getString("client_071");
TC_080=rs.getString("client_080");
TC_170=rs.getString("client_170");

TC_171=rs.getString("client_171");

remarks=rs.getString("remarks");

//out.println("remarks"+remarks);


%>


<tr class="data1">
<td>

<% out.println("<input size = \"2\" type=\"text\" name=\"SNo" + SNo+ "\" value=\"" + SNo+ "\">");%>

</td>

<td>
<% out.println("<input size = \"10\" type=\"text\" name=\"req_no" + SNo+ "\" value=\"" + req_no+ "\">");%>

</td>

<td>

<%
out.println("<input type=\"text\" name=\"desc" + SNo+ "\" value=\"" + rs.getString("descs")+ "\">");

%>

</td>

<td>

<%
out.println("<select name=\"WB_CUS" +SNo+ "\" >");

%>

<%
if (WB_CUS.equals("WB"))
{%>
<option value=<%=WB_CUS%> ><%=WB_CUS%></option> <option value="CUS">CUS</option></td>
<%}else{%>
<option value=<%=WB_CUS%> ><%=WB_CUS%></option> <option value="WB">WB</option></td>
<%}%>

</td>

<td>


<%
out.println("<input type=\"text\" size = \"8\" name=\"req_date" + SNo+ "\" value=\"" + req_date+ "\">");

%>

</td>

<td>

<%
out.println("<input type=\"text\" name=\"req_by" + SNo+ "\" value=\"" + req_by + "\">");

%>

</td>
<td>
<%
out.println("<select name=\"souce" +SNo+ "\" >");

%><option value="060">060</option></select></td>
</td>


<%
if(TC_070.equals("Transport"))
temp_trans="open";
else
temp_trans=TC_070;
%>
<td>
<%
if((TC_070.equals("Transport")) ||(TC_070.equals("NA") ))
{
out.println("<select name=\"TC_070" +SNo+ "\" >");
}
else
{
out.println("<select name=\"TC_070" +SNo+ "\" disabled>");
}
%>
<option value=<%=TC_070%>><%=temp_trans%></option>
<%
if (TC_070.equals("NA"))
{%>
<option value="open">open</option>
<%}%>
<%
if (TC_070.equals("Transport"))
{%>
<option value="NA">NA</option>
<%}%>

<option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option><option value="8">8</option><option value="cancel">cancel</option>
</td>



<%
if(TC_071.equals("Transport"))
temp_trans="open";
else
temp_trans=TC_071;
%>
<td>
<%
if((TC_071.equals("Transport")) ||(TC_071.equals("NA") ))
{
out.println("<select name=\"TC_071" +SNo+ "\" >");
}
else
{
out.println("<select name=\"TC_071" +SNo+ "\" disabled>");
}
%>
<option value=<%=TC_071%>><%=temp_trans%></option>
<%
if (TC_071.equals("NA"))
{%>
<option value="open">open</option>
<%}%>
<%
if (TC_071.equals("Transport"))
{%>
<option value="NA">NA</option>
<%}%>

<option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option><option value="8">8</option><option value="cancel">cancel</option>
</td>



<%
if(TC_080.equals("Transport"))
temp_trans="open";
else
temp_trans=TC_080;
%>
<td>
<%
if((TC_080.equals("Transport")) ||(TC_080.equals("NA") ))
{
out.println("<select name=\"TC_080" +SNo+ "\" >");
}
else
{
out.println("<select name=\"TC_080" +SNo+ "\" disabled>");
}
%>
<option value=<%=TC_080%>><%=temp_trans%></option>
<%
if (TC_080.equals("NA"))
{%>
<option value="open">open</option>
<%}%>
<%
if (TC_080.equals("Transport"))
{%>
<option value="NA">NA</option>
<%}%>

<option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option><option value="8">8</option><option value="cancel">cancel</option>
</td>



<%
if(TC_170.equals("Transport"))
temp_trans="open";
else
temp_trans=TC_170;
%>
<td>
<%
if((TC_170.equals("Transport")) ||(TC_170.equals("NA") ))
{
out.println("<select name=\"TC_170" +SNo+ "\" >");
}
else
{
out.println("<select name=\"TC_170" +SNo+ "\" disabled>");
}
%>
<option value=<%=TC_170%>><%=temp_trans%></option>
<%
if (TC_170.equals("NA"))
{%>
<option value="open">open</option>
<%}%>
<%
if (TC_170.equals("Transport"))
{%>
<option value="NA">NA</option>
<%}%>

<option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option><option value="8">8</option><option value="cancel">cancel</option>
</td>


<%
if(TC_171.equals("Transport"))
temp_trans="open";
else
temp_trans=TC_171;
%>
<td>
<%
if((TC_171.equals("Transport")) ||(TC_171.equals("NA") ))
{
out.println("<select name=\"TC_171" +SNo+ "\" >");
}
else
{
out.println("<select name=\"TC_171" +SNo+ "\" disabled>");
}
%>
<option value=<%=TC_171%>><%=temp_trans%></option>
<%
if (TC_171.equals("NA"))
{%>
<option value="open">open</option>
<%}%>
<%
if (TC_171.equals("Transport"))
{%>
<option value="NA">NA</option>
<%}%>

<option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option><option value="8">8</option><option value="cancel">cancel</option>
</td>

<td>
<%
out.println("<input type=\"text\" size = \"14\" name=\"remarks" + SNo+ "\" value=\"" + remarks+ "\">");

%>

</td>
<td>



<button type="button" OnClick ="update_query(<%=SNo%>);"/>Update</button>


</td>



</tr>
<%
}
%>
</table>
</table>
<input type="hidden" size = "9" name="flag" value="flag" />
<%


con.close();


}catch(Exception e)
{
// con.close();
out.println("Exception in connection : " + e.toString());
}
%>
</form>
</div>
</body>
</html>

priyapratheep
05-24-2009, 08:37 PM
pls help

venegal
05-24-2009, 11:04 PM
Did you even read what Old Pedant wrote before bumping your thread 10 minutes after your last post?

You have to id your field.

And the line remarks_1.disabled = true; is nowhere to be found in your code.

priyapratheep
05-25-2009, 08:04 PM
if(TC_070_1.value=="cancel" || TC_071_1.value=="cancel" || TC_080_1.value=="cancel" || TC_171_1.value=="cancel")
{
alert("succ");
req_no.disabled="True";
req_no.readOnly="True";
desc.disabled="True";


req_no_1.disabled="True";
req_no_1.readOnly="True";
desc.disabled="True";

//document.f_update.req_no_1.disabled="true";
//document.f_update.req_no1.readOnly = true;


remarks_1.disabled=true;
document.f_update.remarks_1.readOnly = true;

}

just i changed the name to test

pls help

Old Pedant
05-25-2009, 08:22 PM
You do this:


function update_query(a)
{
...
var TC_070="TC_070"+a
var TC_070_1=document.getElementById(TC_070)

Let's assume that you call that via update_query(1)

Okay, so then *EFFECTIVELY* you are doing


var TC_070_1=document.getElementById("TC_0701")

But when you *create* the TC_070 <select>s with your JSP code, you do *NOT* give them an ID. If you don't give them an ID, you can *NOT* use getElementById!!!! You generate them here:


out.println("<select name=\"TC_070" +SNo+ "\" >");

You see any ID in there??? No? I don't, either.

MORE THAN THAT...
You *NEVER* put a </select> onto the end of *ANY* of your <select>s!!!

IF YOU DO NOT properly create form fields, then the WILL NOT APPEAR in the DOM and you will never be able to find them.

That entire page of code is a real mish-mash and it's hard to tell what the purpose is, but clearly it needs a *LOT* or rework and rewrite.

I wish you luck. I think you have several days of work ahead of you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum