-
I have a text box on a form but don't want it to be changed. I've used the tip from http://webreference.com/js/tips/991114.html to make sure that the user can not press keys to change it. My problem is is that the user can still cut from this text box. I thought about using the script to cut out the right mouse button click, but then there is still a cut in the Edit menu in Explorer.
I do have a hidden text box as well with the text box I don't want changing, but to use this I need something like an onChange statement that can tell if text has been cut from the text box to implement it, but I can't find one that does this.
I can't use plain text before anyone says anything because I use some JavaScript to change this text, and I can't find anyway of using JavaScript to change normal text even with using CSS.
Hope I've explained myself OK and everyone understands what I'm on about and can help!!
-
DIV block for CSS?
The follwing example uses plain text and allows the modification of the text programatically.
To prove this also works with a CSS, I have included a style section which can be moved to a stylesheet if you prefer.
Code:
<html>
<head>
<title>Modify text programatically in a webpage</title>
<script language="VBScript">
<!--
Sub ChangeText()
Select Case oText.innerText
Case "Text"
oText.innerText = "The text has changed!"
Case "The text has changed!"
oText.innerText = "Text"
End Select
End Sub
-->
</script>
<style>
DIV.mycss
{
FONT-WEIGHT: bold;
COLOR: red
}
</style>
</head>
<body>
<p>
<div class="mycss">
This is some test <a id="oText">Text</a>
</div>
</p>
<input type="button" name="oButton" value="Change Text" onclick="ChangeText"></input>
</body>
</html>
This is a lot easier to use than trying to capture the changes to a disabled text box!
Let me know if this works! :cool:
-
That works fine with ten of my labels. But for some reason however much I try the following two will not change:
<a id="status"></a> and <a id="location"></a>. Any idea why?
-
Try to name your objects without using reserved words. This may cause unreported errors:
Code:
<a id="oStatus"></a> and <a id="oLocation"></a>
P.S. You can use the <span> tag instead of an <a> tag if you prefer.
-
of course!
yep that works fine now. Cheers very much for your help.