Click to See Complete Forum and Search --> : place text in input field


lakshman
05-01-2003, 03:22 AM
Hi

Please help me if you can. Thanks in advance.

I have jsp structure as follows

Form frmTab
Div id=p1panel1
table tblApplication
input txtFName

When I try
document.frmTab.p1panel1.tblApplication.txtFName.value="Lakshman";
I get an ERROR:document.frmTab.p1panel1.tblApplication is null or not an object.

when I try
document.frmTab.p1panel1.tblApplication.border=1; I get the same error.


when I try
document.frmTab.p1panel1.txtFName.value="Lakshman";
I get an ERROR:document.frmTab.p1panel1.txtFName is null or not an object.

Is it that these obejcts have not yet bean created ??
How do I set the border and txtFName ???
-------------------------------------------------------------------

document.frmTab.style.visibility = "hidden";
work fine. ie frmTab is an object.

-------------------------------------------------------------------
Interestingly enough when I try
document.frmTab.p1panel1.style.zIndex=5;
I get an ERROR : document.frmTab.p1panel1.style null or not an object

But when I do this :
p1panel1.style.zIndex=5;
works fine.

why ??? I thought p1panel1 is a child of frmTab but obviously not.

1. Where can I get a document explaining all this.
2. Details on how to use object attribute ie.
in HTML <div style="z-index:4">
but in JS style.zIndex=4

Thanks.

beebob
05-01-2003, 03:26 AM
try the same things within a function

function whatever(){
// your code

}

lakshman
05-01-2003, 03:33 AM
Sorry I did not make it clear, but all the JS stuff is done in a function.

beebob
05-01-2003, 03:37 AM
could you please post the full code?

gnanesh
05-01-2003, 06:07 AM
Try by giving


document.all.p1panel1.tblApplication.txtFName.value = "some value"
or
document.all.txtFName.value ="some value"

Instead of

document.frmTab.p1panel1.tblApplication.txtFName.value

thanks
gnanesh

khalidali63
05-01-2003, 09:29 AM
you are doing it wrong..
document.frmTab.p1panel1.tblApplication.txtFName.value="Lakshman";
the correct structure to reference an html element is as below
document.formName.elementName.value..

in your case it will be

document.frmTab.txtFName.value="Lakshman";

if you want to reference an html element by its id then the correct structure will be like this

say your text field has id="lakshman_1"

var el = document.getElementById("lakshman_1");
now you can access this elements value or attributes
el.value="lakshman" and so on..

lakshman
05-01-2003, 07:29 PM
Hi bob,
I have attached the full code.

Hi gnanesh,
I tried your way but did not work. If you look at khalid's comment -- "if you want to reference an html element by its id...." -- Could this be the reason your suggestion did not work ?


Hi khalid,

I tried your suggestion too but to no avail.


Hi All

Could you please reffer me to a good book or web site where I can read more about all this.
eg 1) To refer an element by Id do .....
2) Details on how to use object attribute ie.
in HTML do <div style="z-index:4">
but in JS do style.zIndex=4

I currently use http://www.w3schools.com but I don't seem to find all the information.

"Give man a fish and feed him for a day. Show him how to fish and feed him for life."

khalidali63
05-01-2003, 07:49 PM
Originally posted by lakshman
Hi khalid,
I tried your suggestion too but to no avail.
........

What I posted was not a solution,its the correct syntax to refer an object and then get it to do something ,e.g give an html element a value

document.frmTab.txtFName.value="Lakshman";

in the above,
frmTab represents the name of the form.
txtFName represents the name of the text field.
value is an attribute for this text field who's value is being set to "lakshman"
If you say that does not work..that means you have not implemented the code correctly,and there are way more erros in other places of your code.

EDIT:
I took a look at your code,Your question confuses me,what are you trying to do?
If your concern is submitting the form, you dont have to set any values,by default they will be contained in the HTTP request object to your jsp.
Please be more descriptive that what is you intend to your code to do and what its not doing....

lakshman
05-01-2003, 08:27 PM
Hi khalid,

First allow me to thank you for your effort.

Secondly.

In my code there is a line
<input type="text name="txtFName" value="" size="40" maxlength="50"/>

I need to put a text in it. A text, that I will get from the database. I have not coded the database retrieval part yet.
But if I know how to do it in my JS Function then I can implement the DB part.


Thanks again.

lakshman
05-04-2003, 07:56 PM
Hi khalid,

I had the weekend to review my program, and you were right, "there was way more errors in other places in my code".

After correcting them, all works fine.

I was using a code from another developer as a basis. I thought it was all correct. How wrong I was.

Thanks again for your help.