Connecting Tech Pros Worldwide Forums | Help | Site Map

Updating a texbox with Javascript

Denise
Guest
 
Posts: n/a
#1: Nov 19 '05
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

Eliyahu Goldin
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Updating a texbox with Javascript


Did you try document.getElementById('myText')?

Eliyahu

"Denise" <Denise@discussions.microsoft.com> wrote in message
news:908F31DC-3B89-4ED9-A8D9-B21AAADCE67C@microsoft.com...[color=blue]
> I am working with some pre-written code that dynamically builds a page[/color]
with[color=blue]
> 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[/color]
page.[color=blue]
> 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[/color]
controls.[color=blue]
>
> Here is a very simlified view of what I see when I selece View/Source from[/color]
IE:[color=blue]
>
> <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[/color]
anything[color=blue]
> to do with it? Is there any other way I can get at the field in this
> scenario?
>
> Thanks in advance,
> Denise[/color]


Denise
Guest
 
Posts: n/a
#3: Nov 19 '05

re: Updating a texbox with Javascript


> 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" wrote:
[color=blue]
> Did you try document.getElementById('myText')?
>
> Eliyahu
>
> "Denise" <Denise@discussions.microsoft.com> wrote in message
> news:908F31DC-3B89-4ED9-A8D9-B21AAADCE67C@microsoft.com...[color=green]
> > I am working with some pre-written code that dynamically builds a page[/color]
> with[color=green]
> > 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[/color]
> page.[color=green]
> > 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[/color]
> controls.[color=green]
> >
> > Here is a very simlified view of what I see when I selece View/Source from[/color]
> IE:[color=green]
> >
> > <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[/color]
> anything[color=green]
> > to do with it? Is there any other way I can get at the field in this
> > scenario?
> >
> > Thanks in advance,
> > Denise[/color]
>
>
>[/color]
Denise
Guest
 
Posts: n/a
#4: Nov 19 '05

re: Updating a texbox with Javascript


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" wrote:
[color=blue][color=green]
> > Did you try document.getElementById('myText')?[/color]
> 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" wrote:
>[color=green]
> > Did you try document.getElementById('myText')?
> >
> > Eliyahu
> >
> > "Denise" <Denise@discussions.microsoft.com> wrote in message
> > news:908F31DC-3B89-4ED9-A8D9-B21AAADCE67C@microsoft.com...[color=darkred]
> > > I am working with some pre-written code that dynamically builds a page[/color]
> > with[color=darkred]
> > > 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[/color]
> > page.[color=darkred]
> > > 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[/color]
> > controls.[color=darkred]
> > >
> > > Here is a very simlified view of what I see when I selece View/Source from[/color]
> > IE:[color=darkred]
> > >
> > > <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[/color]
> > anything[color=darkred]
> > > to do with it? Is there any other way I can get at the field in this
> > > scenario?
> > >
> > > Thanks in advance,
> > > Denise[/color]
> >
> >
> >[/color][/color]
Closed Thread