By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

how to make the textbox become unchangable..

100+
P: 102
beginner here..hahahha...

how can i change the textbox become unchangable ar>??? can see but cannot change...
Jun 20 '07 #1
Share this Question
Share on Google+
4 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

use:

Expand|Select|Wrap|Line Numbers
  1. var textbox = document.getElementById('your_textbox_id');
  2.  
  3. // to make it readonly
  4. textbox.setAttribute('readonly', 'true');
  5.  
  6. // to enable it
  7. textbox.removeAttribute('readonly');
kind regards ...
Jun 20 '07 #2

100+
P: 102
hi ...

use:

Expand|Select|Wrap|Line Numbers
  1. var textbox = document.getElementById('your_textbox_id');
  2.  
  3. // to make it readonly
  4. textbox.setAttribute('readonly', 'true');
  5.  
  6. // to enable it
  7. textbox.removeAttribute('readonly');
kind regards ...
sorryy.. my javascript suck...!!!

i put
<head>
<script language="javascript">
var textbox = document.getElementById('Part');

textbox.setAttribute('readonly', 'true');

</script></head>


my textbox name=Part and id= part

why i cant get the readonly result
Jun 20 '07 #3

gits
Expert Mod 5K+
P: 5,390
... wrap it in a function and call it onload of your body ... this will work ;)

in case you want to have the textbox always readonly then you may do:

[HTML]<input type="text" name="whatever_name" id="whatever_id" readonly="true"/>[/HTML]

this works too ... ! in case you want to enable it during runtime ... call a function that removes the attribute the way i showed you ...

kind regards ...

explaination: onload of the document's body all elements are already rendered by the browser engine and then you may refer to them using javascript ... the way you did javascript should throw an error from getElementById() ... have a look at the js-console
Jun 20 '07 #4

100+
P: 102
thank you very much,.... i am new but granted a proj in javascript...hahah...

can u help me on this quetions...

let say i have 100 textbox and i update 10 out of that ... how do i display those only updated textbox with color??...thanks

-------------------------------------------------------------------------------------------------------------
function foo(){
document.getElementById('test').className='input2'
}

</script>
<style type=text/css>
.input {background: #ff2345; }
.input2 {background: #987654; }

</style>


<input class=input id=test type=text>
<a href=javascript:foo()>click here</a>
=------------------------------------------------------------------------------------------

they told me to do in this way.. but when i click on my update button.. it will actually go to another page to get the update function before redirect to this page ... how i show only updated textbox with color
Jun 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.