Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting some ASP to Javascript

Status
Not open for further replies.

Sfixphdi

Technical User
Nov 22, 2005
4
US
Thanks in advance for taking the time to read this. Below is some ASP VB code that I'm trying to change to Javascript so I'm not limited to Windows web servers. There is much more to it, but I didn't want to post the entire web page code here. You can access the result at Anyway, as you can see, I am defining default variables using if/then/else statements. Then, a users is able to change these variables by a simple POST form that just reloads the same page with the new variables. What I can't seem to do is have the variables print in the proper areas using Javascript, and I also cannot get the form to work. Perhaps I will need a separate form handling script since I'm trying to switch from server-side to client-side scripting? Thanks!

<%
if Request.form("height") = "" then
height = "400"
else
height = Request.form("height")
end if
if Request.form("width") = "" then
width = "620"
else
width = Request.form("width")
end if
%>

//html stuff

<SCRIPT LANGUAGE=javascript>
<!--
var codebase="if (navigator.userAgent.toUpperCase().indexOf("MAC") >= 0)
document.write("<APPLET codebase=\""+codebase+"\" CODE=\"javAPRS.class\" archive=\"japrsmac.jar\" WIDTH=<%Response.write width%> HEIGHT=<%Response.write height%>>");
else
{
document.write("<APPLET codebase=\""+codebase+"\" CODE=\"javAPRS.class\" archive=\"japrs.jar\" WIDTH=<%Response.write width%> HEIGHT=<%Response.write height%>>");
document.write("<param name=\"cabbase\" value=\"japrs.cab\">");
}
// -->
</SCRIPT>

//html stuff

<FORM METHOD="Post" action="bakervegas.asp">
Enter Map Width (pixels): <INPUT TYPE="Text" NAME="width" VALUE="<%Response.write width%>" SIZE="4">&nbsp
Enter Map Height (pixels): <INPUT TYPE="Text" NAME="height" VALUE="<%Response.write height%>" SIZE="4">
<P><INPUT TYPE="Submit" VALUE="Customize" NAME="Size"></FORM></P>
 
I do not believe you can read values submitted with the Post method within Javascript. You are currently using ASP to grab the posted values which will work but you said you were trying to remove reliance on ASP.

In any event, when you are trying to get an ASP variable to display in your HTML you use <%=variablename%>. You do not need to do the response.write but you DO need the = sign in front of the variable name.
So your code would be:
Code:
<%
  if Request.form("height") = "" then
    height = "400" 
  else 
    height = Request.form("height")
  end if
  if Request.form("width") = "" then
    width = "620"
  else 
    width = Request.form("width")
  end if
%>

//html stuff

<SCRIPT LANGUAGE=javascript>
<!--
var codebase="[URL unfurl="true"]http://members.dslextreme.com/users/baker2vegas/javAPRS/";[/URL]
if (navigator.userAgent.toUpperCase().indexOf("MAC") >= 0)
    document.write("<APPLET codebase=\""+codebase+"\" CODE=\"javAPRS.class\" archive=\"japrsmac.jar\" WIDTH=<%Response.write width%> HEIGHT=\"<%=height%>\">");
else
{
    document.write("<APPLET codebase=\""+codebase+"\" CODE=\"javAPRS.class\" archive=\"japrs.jar\" WIDTH=<%Response.write width%> HEIGHT=\"<%=height%>\">");
    document.write("<param name=\"cabbase\" value=\"japrs.cab\">");
}
// -->
</SCRIPT>

//html stuff

<FORM METHOD="Post" action="bakervegas.asp">
Enter Map Width (pixels): <INPUT TYPE="Text" NAME="width" VALUE="<%=width%>" SIZE="4">&nbsp
Enter Map Height (pixels): <INPUT TYPE="Text" NAME="height" VALUE="<%=height%>" SIZE="4">
<P><INPUT TYPE="Submit" VALUE="Customize" NAME="Size"></FORM></P>

Paranoid? ME?? WHO WANTS TO KNOW????
 
theniteowl,

I think that Sfixphdi was talking about converting server-side VB to server-side JavaScript, rather than client-side JavaScript.

While most ASP developers use VBScript, a handful use JavaScript - as I do whenever I have call to use ASP.

I would change this:

Code:
<%
  if Request.form("height") = "" then
    height = "400"
  else
    height = Request.form("height")
  end if
  if Request.form("width") = "" then
    width = "620"
  else
    width = Request.form("width")
  end if
%>

to this:

Code:
<%
	if (Request.form('height') == '')
		height = '400';
	else
		height = Request.form('height');

	if (Request.form('width') == '')
		width = '620';
	else
		width = Request.form('width');
%>

or even this, if you prefer:

Code:
<%
	height = ((h = Request.form('height')) == '') ? '400' : h;
	width = ((w = Request.form('width')) == '') ? '620' : w;
%>

and this:

Code:
<%Response.write width%>

to this:

Code:
<% Response.write(width); %>

Don't forget to do the height, too!

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Sorry about not using the code box on my first post - I'll learn! Thanks for the help so far - it has enabled me to clean up my existing code a bit. However, the goal is really to get out of using ASP altogether, so I'm not limited to hosting this site on a Windows box. Would there be a way to have the variables contained in a form handling script and use JavaScript and a GET method to make it work? I'm trying everything I know (and most of what I don't). Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top