Updating a texbox with Javascript

G

Guest

I am working with some pre-written code that dynamically builds a page with
user controls based on data. I need to attach my Javascript to one of the
controls on the form - I do not have access to the code of the master page.
Because of this my <javascript> ends up inside the <form> tag. I want to
simply update some textboxes from a grid using Javascript but it does not
work.

I know that you are not supposed to have the script within the form, but I
am not at liberty to change the setup - I'm just writing one of the controls.

Here is a very simlified view of what I see when I selece View/Source from IE:

<HTML>
<HEAD>
<title>My Title </title>
<link href="Includes/styles.css" rel="stylesheet">
</HEAD>
<body id="webMainPage">
<form name="_ctl0" method="post" action="…" language="javascript"
onsubmit="ValidatorOnSubmit();" id="_ctl0">

<script language="javascript">
function GridRowSelect() {
document.forms[0].elements['myText'].value = 'Deos not work';
document._ctl0.myText.value = ‘Doesn’t work either’; }
</script>

<TABLE id="Table1">
<tr><td> …
</form>
</body>
</HTML>

All of the javascript code for the grid control is generated within the
<form> tags and it seems to work fine. Would SmartNavigation have anything
to do with it? Is there any other way I can get at the field in this
scenario?

Thanks in advance,
Denise
 
G

Guest

Did you try document.getElementById('myText')?
Yes. When I try:
var x1 = document.getElementById('IDText');
x1.value = "does it work?"
I get the error:
Microsoft JScript runtime error: 'null' is null or not an object

Denise


Eliyahu Goldin said:
Did you try document.getElementById('myText')?

Eliyahu

Denise said:
I am working with some pre-written code that dynamically builds a page with
user controls based on data. I need to attach my Javascript to one of the
controls on the form - I do not have access to the code of the master page.
Because of this my <javascript> ends up inside the <form> tag. I want to
simply update some textboxes from a grid using Javascript but it does not
work.

I know that you are not supposed to have the script within the form, but I
am not at liberty to change the setup - I'm just writing one of the controls.

Here is a very simlified view of what I see when I selece View/Source from IE:

<HTML>
<HEAD>
<title>My Title </title>
<link href="Includes/styles.css" rel="stylesheet">
</HEAD>
<body id="webMainPage">
<form name="_ctl0" method="post" action="." language="javascript"
onsubmit="ValidatorOnSubmit();" id="_ctl0">

<script language="javascript">
function GridRowSelect() {
document.forms[0].elements['myText'].value = 'Deos not work';
document._ctl0.myText.value = 'Doesn't work either'; }
</script>

<TABLE id="Table1">
<tr><td> .
</form>
</body>
</HTML>

All of the javascript code for the grid control is generated within the
<form> tags and it seems to work fine. Would SmartNavigation have anything
to do with it? Is there any other way I can get at the field in this
scenario?

Thanks in advance,
Denise
 
G

Guest

I found a solution. The reason the standard javascript reference did not
work is because the page is being dynamically created from several user
controls. A textbox that I named 'IDText' is being renamed _ctl1_IDText.
This syntax works:

this.document.forms[0].elements['_ctl1_IDText'].value = "working!";


Denise said:
Did you try document.getElementById('myText')?
Yes. When I try:
var x1 = document.getElementById('IDText');
x1.value = "does it work?"
I get the error:
Microsoft JScript runtime error: 'null' is null or not an object

Denise


Eliyahu Goldin said:
Did you try document.getElementById('myText')?

Eliyahu

Denise said:
I am working with some pre-written code that dynamically builds a page with
user controls based on data. I need to attach my Javascript to one of the
controls on the form - I do not have access to the code of the master page.
Because of this my <javascript> ends up inside the <form> tag. I want to
simply update some textboxes from a grid using Javascript but it does not
work.

I know that you are not supposed to have the script within the form, but I
am not at liberty to change the setup - I'm just writing one of the controls.

Here is a very simlified view of what I see when I selece View/Source from IE:

<HTML>
<HEAD>
<title>My Title </title>
<link href="Includes/styles.css" rel="stylesheet">
</HEAD>
<body id="webMainPage">
<form name="_ctl0" method="post" action="." language="javascript"
onsubmit="ValidatorOnSubmit();" id="_ctl0">

<script language="javascript">
function GridRowSelect() {
document.forms[0].elements['myText'].value = 'Deos not work';
document._ctl0.myText.value = 'Doesn't work either'; }
</script>

<TABLE id="Table1">
<tr><td> .
</form>
</body>
</HTML>

All of the javascript code for the grid control is generated within the
<form> tags and it seems to work fine. Would SmartNavigation have anything
to do with it? Is there any other way I can get at the field in this
scenario?

Thanks in advance,
Denise
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top