Click to See Complete Forum and Search --> : instruction text visible/hidden
rogers
09-17-2003, 10:12 AM
Hello,
I have an instruction text to the user which I want to make hidden or visible at the appropiate circumstances. Since the instruction is not a user entry field, how do I refer to the instruction text and make hidden or visible?
Thanks
Khalid Ali
09-17-2003, 10:15 AM
please rephrase your question.
rogers
09-17-2003, 10:21 AM
Hi Khalid,
In a form, I am providing an instruction to the user such as "To delete a row, please click on the checkbox and click on the delete button".
I want to be able to make that text hidden or visible.
How do I do that?
If it was a form field, I would do something like:
document.form.field.style.visible = "hidden"
But this is not a field, it is simply a text string.
Is there a way to refer to that string?
Thanks
AdamGundry
09-17-2003, 10:27 AM
I think you need to assign an id to the element containing the text, for example:
<div id="instructionText">This is some text which will appear and disappear.</div>
You can then refer to it using document.getElementById, like this:
document.getElementById('instructionText').style.visible = "hidden"
Adam
rogers
09-17-2003, 10:35 AM
Adam,
How do initially make it hidden, when the form first appears?
AdamGundry
09-17-2003, 10:46 AM
Using CSS:
<div id="instructionText" style="visibility: hidden">
Adam
P.S. Just noticed that in my previous example, it should be "visbility" not "visible".
rogers
09-17-2003, 10:59 AM
Adam,
That looks good. Thanks.
Suppose a user enter a value in a form field.
How do I get the number of character user entered into that field? The field is 2 character in length and I want to check if the user entered 2 character. If user entered only 1 character, I want to used alert().
AdamGundry
09-17-2003, 11:09 AM
You can use String.length, for example:
var myStr = 'a';
if (myStr.length != 2){
alert('You must enter 2 characters!');
}
Adam
rogers
09-17-2003, 11:21 AM
Here is what I tried but did not work.
var astr;
astr = document.formname.fieldname.value;
document.write("len = " + astr.lengh);
I got "len is undefined", even though the field had 1 character in it.
AdamGundry
09-17-2003, 11:29 AM
You missed out the t:
document.write("len = " + astr.length);
Adam
rogers
09-17-2003, 12:20 PM
Adam,
The instruction text is not becoming visible and I am getting the following error:
document.fundingform.instructionText.style is null or not an object.
Here is what I have in the form:
<div id="instructionText" style="visibility:hidden">To delete a row from the table below, check the box and click delete button.</div>
Then in the javascript function I have:
var numrows = document.getElementById("tableID").rows.length;
if (numrows == 0)
{ document.fundingform.instructionText.style.visibility="hidden";
}
else
{ document.fundingform.instructionText.style.visibility="visible";
}
Thanks
AdamGundry
09-17-2003, 01:19 PM
This is not a form field, so in place of
document.fundingform.instructionText.
you need to use
document.getElementById('instructionText').
Adam
rogers
09-17-2003, 01:45 PM
Adam,
Everything works fine :)
Thanks for your help.