-
Pass asp variable to javascript
I have a variable inside an asp block and I want to pass the value to a variable
inside a javascript function. In fact What I want is to set a hidden form
element with the asp variable. Any help will be appreciated
Suresh
-
Re: Pass asp variable to javascript
Hi,
We can do the following to set a hidden form element with the asp variable:
<%
the_value = "test"
%>
.........
<input type = "hidden" name = "the_name" value = "<%= the_value %>">
Would it work for you?
kv-
"suresh" <stgsuresh@hotmail..com> wrote:
>
>I have a variable inside an asp block and I want to pass the value to a
variable
>inside a javascript function. In fact What I want is to set a hidden form
>element with the asp variable. Any help will be appreciated
>
>Suresh
-
Re: Pass asp variable to javascript
well, u can set the asp variable to the hidden form element and extract that
form hidden element from the javascript.. like...
this is how u assign the value to the hidden variable at ur ASP code..
<% strmyVar ="hello" %>
<input name=hidhello value= <%=strmyVar%> >
now to use this variable in ur javascript, extract the value using this statement..
var strTemp
temp = document.form.hidhello.value;
alert(temp);
...
suresh,hope this helps u....
"suresh" <stgsuresh@hotmail..com> wrote:
>
>I have a variable inside an asp block and I want to pass the value to a
variable
>inside a javascript function. In fact What I want is to set a hidden form
>element with the asp variable. Any help will be appreciated
>
>Suresh
-
Re: Pass asp variable to javascript
All of the ways previously posted will work but a technique that I think is
really helpful is to pass the value of an ASP variable as a string to a Javascript
variable.
Example:
<%
dim ASPvar
ASPvar = "hello world"
%>
<script language=javascript>
var Jvar = '<%= ASPvar%>'
</script>
Jvar will contain the value "hello world"
"Kimoanh T. Vo" <kvo@dreamworks.com> wrote:
>
>Hi,
>
>We can do the following to set a hidden form element with the asp variable:
>
><%
>the_value = "test"
>%>
>.........
><input type = "hidden" name = "the_name" value = "<%= the_value %>">
>
>Would it work for you?
>
>kv-
>
>
>
>"suresh" <stgsuresh@hotmail..com> wrote:
>>
>>I have a variable inside an asp block and I want to pass the value to a
>variable
>>inside a javascript function. In fact What I want is to set a hidden form
>>element with the asp variable. Any help will be appreciated
>>
>>Suresh
>
-
Re: Pass asp variable to javascript
Hi Suresh,
I guess you would want to pass the value of an ASP variable to a JS function,
which you can do like this :-
<%
aspvar = "Hi"
%>
<input type=button onclick=butClick('<%=aspvar%>')>
<input type=hidden name=hiddenvar>
<script language=javascript>
function butClick(val)
{
alert(val);
document.form.hiddenvar.value = val;
}
</script>
Suresh,I hope this helps u or if it is something I shall help you again !!!
>
>
>
>"suresh" <stgsuresh@hotmail..com> wrote:
>>
>>I have a variable inside an asp block and I want to pass the value to a
>variable
>>inside a javascript function. In fact What I want is to set a hidden form
>>element with the asp variable. Any help will be appreciated
>>
>>Suresh
>
-
Re: Pass asp variable to javascript
Suresh:
Here is what I do:
Response.write "<script LANGUAGE=" & """" & "JavaScript" & """" & ">" & chr(10)
Response.write "function Messaging(val) {" & chr(10)
Response.Write " winname=" & """" & "MessagingWindow" & """" & chr(10)
Response.Write " msgWin=window.open(" & """" & MainURL & "Messaging/Messaging.asp?SiteID="
& SiteID & "&ID=" & """" & "+val,winname," & """" & "width=480,height=480,toolbar=0,scrollbars=0,status=0"
& """" & ")" & chr(10)
Response.Write " if (navigator.appName == " & """" & "Netscape" & """" &
" && parseInt(navigator.appVersion) >= 3)" & chr(10)
Response.Write " { msgWin.focus(); }" & chr(10)
Response.Write " if (navigator.appName == " & """" & "Microsoft Internet
Explorer" & """" & " && parseInt(navigator.appVersion) >= 3)" & chr(10)
Response.Write " { msgWin.focus(); }" & chr(10)
Response.Write " }" & chr(10)
Response.Write "</script>"%>
By doing this, I can pass any variable I need to, whether it be Java or VB.
Hope this helps!
Scott
-
Re: Pass asp variable to javascript
Suresh:
Here is what I do:
Response.write "<script LANGUAGE=" & """" & "JavaScript" & """" & ">" & chr(10)
Response.write "function Messaging(val) {" & chr(10)
Response.Write " winname=" & """" & "MessagingWindow" & """" & chr(10)
Response.Write " msgWin=window.open(" & """" & MainURL & "Messaging/Messaging.asp?SiteID="
& SiteID & "&ID=" & """" & "+val,winname," & """" & "width=480,height=480,toolbar=0,scrollbars=0,status=0"
& """" & ")" & chr(10)
Response.Write " if (navigator.appName == " & """" & "Netscape" & """" &
" && parseInt(navigator.appVersion) >= 3)" & chr(10)
Response.Write " { msgWin.focus(); }" & chr(10)
Response.Write " if (navigator.appName == " & """" & "Microsoft Internet
Explorer" & """" & " && parseInt(navigator.appVersion) >= 3)" & chr(10)
Response.Write " { msgWin.focus(); }" & chr(10)
Response.Write " }" & chr(10)
Response.Write "</script>"%>
By doing this, I can pass any variable I need to, whether it be Java or VB.
Hope this helps!
Scott
-
Re: Pass asp variable to javascript
Thanks vijay for the tip but actually I am in a different kind of situation
I want to call a asp function/component which will return the next primary
key from a add button. how do I do that
I tried this inside a javascript
next_key = <% = get_next_key() %>
but it does not seem to work ( get_next_key is an asp function which returns
the next key value)
"Vijay" <vijaykumaran@usa.net> wrote:
>
>Hi Suresh,
>
>I guess you would want to pass the value of an ASP variable to a JS function,
>which you can do like this :-
>
><%
>aspvar = "Hi"
>%>
><input type=button onclick=butClick('<%=aspvar%>')>
><input type=hidden name=hiddenvar>
>
><script language=javascript>
>function butClick(val)
>{
>alert(val);
>document.form.hiddenvar.value = val;
>}
></script>
>
>
>Suresh,I hope this helps u or if it is something I shall help you again
!!!
>>
>
>
>
>>
>>
>>"suresh" <stgsuresh@hotmail..com> wrote:
>>>
>>>I have a variable inside an asp block and I want to pass the value to
a
>>variable
>>>inside a javascript function. In fact What I want is to set a hidden
form
>>>element with the asp variable. Any help will be appreciated
>>>
>>>Suresh
>>
>
-
Re: Pass asp variable to javascript
vijay
many thanks.. but my problem is a little more peculiar. I am using powerbuilder
datawindow active x control which is excellent. I just have to update the
form once the user presses the add/update button.
When he presses I want to call my asp function in the onclick event of
the add button which will give me the next key value i tried to call the
asp function inside Javascript like this
var next_key = <% get_nextkey() %> but It does not seem to work
suresh
"Vijay" <vijaykumaran@usa.net> wrote:
>
>Hi Suresh,
>
>I guess you would want to pass the value of an ASP variable to a JS function,
>which you can do like this :-
>
><%
>aspvar = "Hi"
>%>
><input type=button onclick=butClick('<%=aspvar%>')>
><input type=hidden name=hiddenvar>
>
><script language=javascript>
>function butClick(val)
>{
>alert(val);
>document.form.hiddenvar.value = val;
>}
></script>
>
>
>Suresh,I hope this helps u or if it is something I shall help you again
!!!
>>
>
>
>
>>
>>
>>"suresh" <stgsuresh@hotmail..com> wrote:
>>>
>>>I have a variable inside an asp block and I want to pass the value to
a
>>variable
>>>inside a javascript function. In fact What I want is to set a hidden
form
>>>element with the asp variable. Any help will be appreciated
>>>
>>>Suresh
>>
>
-
Re: Pass asp variable to javascript
Your hidden element can look like this:
<INPUT TYPE="HIDDEN" VALUE="<%=aspvar%>"
Then in the function window.onload() on the client script, you can retrieve
this value from the hidden field. By processing it in the onload event,
you ensure that the page with the hidden element has been fully rendered.
You can then post the form/page to itself to make another round trip to the
server in order to get the next value.
"suresh" <stgsuresh@excite.com> wrote:
>
>Thanks vijay for the tip but actually I am in a different kind of situation
>I want to call a asp function/component which will return the next primary
>key from a add button. how do I do that
>I tried this inside a javascript
>
> next_key = <% = get_next_key() %>
>
>but it does not seem to work ( get_next_key is an asp function which returns
>the next key value)
>
>
>
>"Vijay" <vijaykumaran@usa.net> wrote:
>>
>>Hi Suresh,
>>
>>I guess you would want to pass the value of an ASP variable to a JS function,
>>which you can do like this :-
>>
>><%
>>aspvar = "Hi"
>>%>
>><input type=button onclick=butClick('<%=aspvar%>')>
>><input type=hidden name=hiddenvar>
>>
>><script language=javascript>
>>function butClick(val)
>>{
>>alert(val);
>>document.form.hiddenvar.value = val;
>>}
>></script>
>>
>>
>>Suresh,I hope this helps u or if it is something I shall help you again
>!!!
>>>
>>
>>
>>
>>>
>>>
>>>"suresh" <stgsuresh@hotmail..com> wrote:
>>>>
>>>>I have a variable inside an asp block and I want to pass the value to
>a
>>>variable
>>>>inside a javascript function. In fact What I want is to set a hidden
>form
>>>>element with the asp variable. Any help will be appreciated
>>>>
>>>>Suresh
>>>
>>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|