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

Textbox possibilities

Status
Not open for further replies.

siuk

Programmer
Aug 23, 2001
38
GB
Hi,

I want to be able to disable a text box on my website when a tickbox is pressed. Would this be done by putting something along the lines of:

<input type=checkbox onclick=&quot;document.myform.T1.disable&quot;>

This does not work - can anyone help me?? I also would like to know how to re-activate them too!

thanks alot
 
I'm not sure I follow, do you want to hid the textbox when a button is pressed?? If yes, then try using CSS it may be easier that way then using JS... I have not failed; I merely found 100,000 different ways of not succeding...
 
hi - thanks for your responce - it would be nice to change the text boxs color and make it uneditable. any suggestions?
thanks
 
this will probably only work in ie, and maybe ns 6 but it does what you want.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>Untitled</title>
<script>
function formtest() {
document.thisForm.thisTextBox.style.background = &quot;red&quot;
document.thisForm.thisTextBox.unselectable=&quot;On&quot;
}
</script>
</head>

<body>
<form name=&quot;thisForm&quot;>
<input type=&quot;text&quot; name=&quot;thisTextBox&quot; >
</form>

<a href=&quot;javascript:formtest()&quot;>click me</a>


</body>
</html>
 
Ok, this will change the color of the textbox itself and the changet he color of the font:

<input type=&quot;text&quot; style=&quot;background-color:#000000; color:#FFFFFF;&quot; size=&quot;10&quot; maxlength=&quot;25&quot; readonly>

This will make the background color of the texbox black, the font white and the readonly will do exactly what it says...
Hope this helps...:) I have not failed; I merely found 100,000 different ways of not succeding...
 
twist, i haven't seen this property (unselectable) yet.. where have you found it?
i used to use
formTextObj.disabled=true & it works (ie & nn6, not nn4x)
we have a faq on this subj :)

faq216-795

it (faq) doesn't tells you how you have to do that, only one of the ways (that i found by that time) & i'm just too lazy now to rewrite it.. may be sometime when i'd have some free time (february?) Victor
 
thx :)

.................updated.. OK.:))) Victor
 
Hi Siuk,

I think this is what you want (it only works in IE like twist said):

<script language=&quot;Javascript&quot;>
function distextbox()
{
if (document.myform.CHB1.checked == true)
{
document.myform.T1.disabled = true;
document.myform.T1.style.backgroundColor = '#AAAAAA'
}
else
{
document.myform.T1.disabled = false;
document.myform.T1.style.backgroundColor = '#FFFFFF'
}
}
</script>

<form name=&quot;myform&quot;>
<input type=&quot;checkbox&quot; onmouseup=&quot;javascript:distextbox()&quot; id=&quot;CHB1&quot; name=&quot;CHB1&quot;><br>
<input type=&quot;text&quot; id=&quot;T1&quot; name=&quot;T1&quot;>
</form>

But you don't say if the textbox must be &quot;clean/empty&quot; if the checkbox is clicked. What if the users first fill the textbox and then click the checkbox?

In that case you can use this function:

<script language=&quot;Javascript&quot;>
function distextbox(FieldName)
{
if (document.myform.T1.value.length >= 1)
{
var FillEmpty = window.confirm('You choose to click the checkbox(and disable the textbox), but the Field &quot;' +FieldName+ '&quot; is filled.\n\nClick OK to empty the field automaticaly.\nClick Cancel keep the text');
if (FillEmpty)
{
{
if (document.myform.CHB1.checked == true)
{
document.myform.T1.disabled = true;
document.myform.T1.style.backgroundColor = '#AAAAAA'
document.myform.T1.value = ''

}
else
{
document.myform.T1.disabled = false;
document.myform.T1.style.backgroundColor = '#FFFFFF'

}
}
}
else
{
document.myform.CHB1.checked = false
}
}
else
{
if (document.myform.CHB1.checked == true)
{
document.myform.T1.disabled = true;
document.myform.T1.style.backgroundColor = '#AAAAAA'
}
else
{
document.myform.T1.disabled = false;
document.myform.T1.style.backgroundColor = '#FFFFFF'
}
}
}
</script>

<form name=&quot;myform&quot;>
<input type=&quot;checkbox&quot; onclick=&quot;javascript:distextbox(document.myform.T1.name)&quot; id=&quot;CHB1&quot; name=&quot;CHB1&quot;><br>
<input type=&quot;text&quot; id=&quot;T1&quot; name=&quot;T1&quot;>
</form>

Hope this helps,
Erik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top