By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,705 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,705 IT Pros & Developers. It's quick & easy.

Assign value to textbox via Java script in VB

P: n/a
Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm = window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elemen tname') didn't
work

Thanks for your response.
Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm = window.document.body.all[""TextBox1""]; " & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elemen tname') didn't
work

Thanks for your response.

Nov 19 '05 #2

P: n/a
Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if you are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just use
server code, like TextBox1.Value = myParam. What do you need javascript for
then?

Eliyahu

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
Hi,

I am displaying modal dialog and passing values from the main form to the modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error 'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm =

window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elemen tname') didn't
work

Thanks for your response.


Nov 19 '05 #3

P: n/a
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to the
TextBox on the main form.
It gives error object is required

Thanks

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:O8****************@TK2MSFTNGP12.phx.gbl...
Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
> Hi,
>
> I am displaying modal dialog and passing values from the main form to the > modal dialog and back.
> It works fine but if I used the following syntax on Page_Load(just for
> testing) in VB to assign value form the object to text Box it gives error > 'Object required'
> Dim strResponse As String
> strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
> strResponse = strResponse & "var aForm; " & vbCrLf
> 'Error is on the page- Object required
> strResponse = strResponse & "aForm =

window.document.body.all[""TextBox1""];
> " & vbCrLf
> strResponse = strResponse & "window.alert(aForm); " & vbCrLf
> strResponse = strResponse & "</script>" & vbCrLf
> Response.Write(strResponse)
>
> I want to assign a value from an object to TextBox in Java script but I
> don't know how to refer to TextBox on page.
> Is it - window.document.forms('formname').elements('elemen tname')
> didn't
> work
>
> Thanks for your response.
>
>



Nov 19 '05 #4

P: n/a
It is ASP.Net VB project.

I have got main form.
It opens modal seacrh form. After a user makes a selection it should return
SelectedID to the main form and reload it
My problem is that I can pass object to the modal search form and get values
back but I don't know how to get values from the object in JavaScript in VB
and reload the form.

Thanks

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm =

window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elemen tname') didn't
work

Thanks for your response.


Nov 19 '05 #5

P: n/a
You do it in javascript. Usually hidden text inputs are used to pass values
from client to server.

document.getElementById("myHiddenInput").value=myP aram

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:O9***************@TK2MSFTNGP15.phx.gbl...
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to the TextBox on the main form.
It gives error object is required

Thanks

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:O8****************@TK2MSFTNGP12.phx.gbl...
Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oe**************@TK2MSFTNGP14.phx.gbl...
> Hi,
>
> I am displaying modal dialog and passing values from the main form to

the
> modal dialog and back.
> It works fine but if I used the following syntax on Page_Load(just for > testing) in VB to assign value form the object to text Box it gives

error
> 'Object required'
> Dim strResponse As String
> strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf > strResponse = strResponse & "var aForm; " & vbCrLf
> 'Error is on the page- Object required
> strResponse = strResponse & "aForm =
window.document.body.all[""TextBox1""];
> " & vbCrLf
> strResponse = strResponse & "window.alert(aForm); " & vbCrLf
> strResponse = strResponse & "</script>" & vbCrLf
> Response.Write(strResponse)
>
> I want to assign a value from an object to TextBox in Java script but I > don't know how to refer to TextBox on page.
> Is it - window.document.forms('formname').elements('elemen tname')
> didn't
> work
>
> Thanks for your response.
>
>



Nov 19 '05 #6

P: n/a
Eliyahu,
I have got this code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var myObject = new Object(); " & vbCrLf
strResponse = strResponse & "myObject.guid = '" & strGuid & "'; " & vbCrLf
strResponse = strResponse & "myObject.id = 0; " & vbCrLf
strResponse = strResponse & "// The object myObject is sent to the modal
window. " & vbCrLf
strResponse = strResponse & "var answer =
window.showModalDialog('datagridHyperLink.aspx', myObject,
'dialogHeight:300px; dialogLeft:200px;'); " & vbCrLf
strResponse = strResponse & "document.getElementById('myHiddenInput').valu e=
myObject.id; " & vbCrLf
strResponse = strResponse & "window.alert(myObject.guid); " & vbCrLf
strResponse = strResponse & "window.alert(myObject.id); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

End Sub

I have got error again

document.getElementById(...) is null or not an object

Thanks again

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e$**************@tk2msftngp13.phx.gbl...
You do it in javascript. Usually hidden text inputs are used to pass
values
from client to server.

document.getElementById("myHiddenInput").value=myP aram

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:O9***************@TK2MSFTNGP15.phx.gbl...
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to

the
TextBox on the main form.
It gives error object is required

Thanks

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:O8****************@TK2MSFTNGP12.phx.gbl...
> Just read your message second time.
>
> How do you pass values to the modal dialog? What I wrote was good if
> you
> are
> passing parameters in the second parameter of showModalDialog call.
> Otherwise, if you can access the values on server side, you can just
> use
> server code, like TextBox1.Value = myParam. What do you need javascript
> for
> then?
>
> Eliyahu
>
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:%2***************@TK2MSFTNGP15.phx.gbl...
>> What do you need VB for? Why can't you do everything on the client in
>> javascript in <body ... onload=...> event?
>>
>> Eliyahu
>>
>> "Sergei" <se****@ssw.com.au> wrote in message
>> news:Oe**************@TK2MSFTNGP14.phx.gbl...
>> > Hi,
>> >
>> > I am displaying modal dialog and passing values from the main form
>> > to
> the
>> > modal dialog and back.
>> > It works fine but if I used the following syntax on Page_Load(just for >> > testing) in VB to assign value form the object to text Box it gives
> error
>> > 'Object required'
>> > Dim strResponse As String
>> > strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf >> > strResponse = strResponse & "var aForm; " & vbCrLf
>> > 'Error is on the page- Object required
>> > strResponse = strResponse & "aForm =
>> window.document.body.all[""TextBox1""];
>> > " & vbCrLf
>> > strResponse = strResponse & "window.alert(aForm); " & vbCrLf
>> > strResponse = strResponse & "</script>" & vbCrLf
>> > Response.Write(strResponse)
>> >
>> > I want to assign a value from an object to TextBox in Java script
>> > but I >> > don't know how to refer to TextBox on page.
>> > Is it - window.document.forms('formname').elements('elemen tname')
>> > didn't
>> > work
>> >
>> > Thanks for your response.
>> >
>> >
>>
>>
>
>



Nov 19 '05 #7

P: n/a
I guess the problem is in the way how you sending javascript to client.
Likely, the DHTML object model of your page hasn't been built at this stage,
that's why none of the HTML elements can be found. Why do you need to emit
the javascript in the Response? Why not to put it inside your .aspx page in
the <head> section? BTW, you probably meant

document.getElementById('myHiddenInput').value=ans wer;

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oh**************@TK2MSFTNGP15.phx.gbl...
Eliyahu,
I have got this code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var myObject = new Object(); " & vbCrLf
strResponse = strResponse & "myObject.guid = '" & strGuid & "'; " & vbCrLf
strResponse = strResponse & "myObject.id = 0; " & vbCrLf
strResponse = strResponse & "// The object myObject is sent to the modal
window. " & vbCrLf
strResponse = strResponse & "var answer =
window.showModalDialog('datagridHyperLink.aspx', myObject,
'dialogHeight:300px; dialogLeft:200px;'); " & vbCrLf
strResponse = strResponse & "document.getElementById('myHiddenInput').valu e= myObject.id; " & vbCrLf
strResponse = strResponse & "window.alert(myObject.guid); " & vbCrLf
strResponse = strResponse & "window.alert(myObject.id); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

End Sub

I have got error again

document.getElementById(...) is null or not an object

Thanks again

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e$**************@tk2msftngp13.phx.gbl...
You do it in javascript. Usually hidden text inputs are used to pass
values
from client to server.

document.getElementById("myHiddenInput").value=myP aram

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:O9***************@TK2MSFTNGP15.phx.gbl...
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to

the
TextBox on the main form.
It gives error object is required

Thanks

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:O8****************@TK2MSFTNGP12.phx.gbl...
> Just read your message second time.
>
> How do you pass values to the modal dialog? What I wrote was good if
> you
> are
> passing parameters in the second parameter of showModalDialog call.
> Otherwise, if you can access the values on server side, you can just
> use
> server code, like TextBox1.Value = myParam. What do you need javascript > for
> then?
>
> Eliyahu
>
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:%2***************@TK2MSFTNGP15.phx.gbl...
>> What do you need VB for? Why can't you do everything on the client in >> javascript in <body ... onload=...> event?
>>
>> Eliyahu
>>
>> "Sergei" <se****@ssw.com.au> wrote in message
>> news:Oe**************@TK2MSFTNGP14.phx.gbl...
>> > Hi,
>> >
>> > I am displaying modal dialog and passing values from the main form
>> > to
> the
>> > modal dialog and back.
>> > It works fine but if I used the following syntax on Page_Load(just

for
>> > testing) in VB to assign value form the object to text Box it gives > error
>> > 'Object required'
>> > Dim strResponse As String
>> > strResponse = strResponse & "<script language=""JavaScript"">" &

vbCrLf
>> > strResponse = strResponse & "var aForm; " & vbCrLf
>> > 'Error is on the page- Object required
>> > strResponse = strResponse & "aForm =
>> window.document.body.all[""TextBox1""];
>> > " & vbCrLf
>> > strResponse = strResponse & "window.alert(aForm); " & vbCrLf
>> > strResponse = strResponse & "</script>" & vbCrLf
>> > Response.Write(strResponse)
>> >
>> > I want to assign a value from an object to TextBox in Java script
>> > but

I
>> > don't know how to refer to TextBox on page.
>> > Is it - window.document.forms('formname').elements('elemen tname')
>> > didn't
>> > work
>> >
>> > Thanks for your response.
>> >
>> >
>>
>>
>
>



Nov 19 '05 #8

P: n/a
Found the solution - added smartnavgation="true" and it started working.
I used RegisterStartupScript method
Thanks
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...
I guess the problem is in the way how you sending javascript to client.
Likely, the DHTML object model of your page hasn't been built at this
stage,
that's why none of the HTML elements can be found. Why do you need to
emit
the javascript in the Response? Why not to put it inside your .aspx page
in
the <head> section? BTW, you probably meant

document.getElementById('myHiddenInput').value=ans wer;

Eliyahu

"Sergei" <se****@ssw.com.au> wrote in message
news:Oh**************@TK2MSFTNGP15.phx.gbl...
Eliyahu,
I have got this code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var myObject = new Object(); " & vbCrLf
strResponse = strResponse & "myObject.guid = '" & strGuid & "'; " &
vbCrLf
strResponse = strResponse & "myObject.id = 0; " & vbCrLf
strResponse = strResponse & "// The object myObject is sent to the modal
window. " & vbCrLf
strResponse = strResponse & "var answer =
window.showModalDialog('datagridHyperLink.aspx', myObject,
'dialogHeight:300px; dialogLeft:200px;'); " & vbCrLf
strResponse = strResponse &

"document.getElementById('myHiddenInput').valu e=
myObject.id; " & vbCrLf
strResponse = strResponse & "window.alert(myObject.guid); " & vbCrLf
strResponse = strResponse & "window.alert(myObject.id); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

End Sub

I have got error again

document.getElementById(...) is null or not an object

Thanks again

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e$**************@tk2msftngp13.phx.gbl...
> You do it in javascript. Usually hidden text inputs are used to pass
> values
> from client to server.
>
> document.getElementById("myHiddenInput").value=myP aram
>
> Eliyahu
>
> "Sergei" <se****@ssw.com.au> wrote in message
> news:O9***************@TK2MSFTNGP15.phx.gbl...
>> Yes, I pass an object as the second parameter.
>> But I don't know how to assign a value from the object in JavaScript
>> to
> the
>> TextBox on the main form.
>> It gives error object is required
>>
>> Thanks
>>
>> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
>> news:O8****************@TK2MSFTNGP12.phx.gbl...
>> > Just read your message second time.
>> >
>> > How do you pass values to the modal dialog? What I wrote was good if
>> > you
>> > are
>> > passing parameters in the second parameter of showModalDialog call.
>> > Otherwise, if you can access the values on server side, you can just
>> > use
>> > server code, like TextBox1.Value = myParam. What do you need javascript >> > for
>> > then?
>> >
>> > Eliyahu
>> >
>> > "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
>> > news:%2***************@TK2MSFTNGP15.phx.gbl...
>> >> What do you need VB for? Why can't you do everything on the client in >> >> javascript in <body ... onload=...> event?
>> >>
>> >> Eliyahu
>> >>
>> >> "Sergei" <se****@ssw.com.au> wrote in message
>> >> news:Oe**************@TK2MSFTNGP14.phx.gbl...
>> >> > Hi,
>> >> >
>> >> > I am displaying modal dialog and passing values from the main
>> >> > form
>> >> > to
>> > the
>> >> > modal dialog and back.
>> >> > It works fine but if I used the following syntax on
>> >> > Page_Load(just
> for
>> >> > testing) in VB to assign value form the object to text Box it gives >> > error
>> >> > 'Object required'
>> >> > Dim strResponse As String
>> >> > strResponse = strResponse & "<script language=""JavaScript"">" &
> vbCrLf
>> >> > strResponse = strResponse & "var aForm; " & vbCrLf
>> >> > 'Error is on the page- Object required
>> >> > strResponse = strResponse & "aForm =
>> >> window.document.body.all[""TextBox1""];
>> >> > " & vbCrLf
>> >> > strResponse = strResponse & "window.alert(aForm); " & vbCrLf
>> >> > strResponse = strResponse & "</script>" & vbCrLf
>> >> > Response.Write(strResponse)
>> >> >
>> >> > I want to assign a value from an object to TextBox in Java script
>> >> > but
> I
>> >> > don't know how to refer to TextBox on page.
>> >> > Is it - window.document.forms('formname').elements('elemen tname')
>> >> > didn't
>> >> > work
>> >> >
>> >> > Thanks for your response.
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.