Access an ASP value from Javascript

Could someone help me with this little issue Im having.  Basically I am attempting to reference a html form value from a javascript file.  The problem is that the value for the form field comes from an ASP value, which I dont think the javascript can access.

Heres the HTML
<input type="text" name="OutputFile" value="<%=objMapSvr.OutputFile%>">
And heres the contents of the Javascript file embed.js

var sACGM = document.forms.MapValues.OutputFile.value;

document.writeln ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE=sACGM> <embed name='AXCGM' src=sACGM width='100%' height='100%'> </embed> </object>")
LVL 11
BillPowellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flipzCommented:
What you need to do can be accomplished - just add an ID value in your textbox control the same as the name and change the first line in you JS - I am assuming your form has and ID value of MapValues since you didn't post that part.

<input type="text" name="OutputFile" id="OutputFile" value="<%=objMapSvr.OutputFile%>">
And heres the contents of the Javascript file embed.js

var sACGM = document["MapValues"].OutputFile.value;

document.writeln ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE=sACGM> <embed name='AXCGM' src=sACGM width='100%' height='100%'> </embed> </object>")
0
BillPowellAuthor Commented:
Here is the form itself:
<form NAME="MapValues" action="GenerateMap.asp" target="frmHid" method=post>
0
flipzCommented:
Just add ID value - let me know if you have problems when you make the changes:

<form NAME="MapValues" ID="MapValues" action="GenerateMap.asp" target="frmHid" method=post>
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

flipzCommented:
BTW - you may have to encode the output value from ASP so that you don't get any problem characters:

<input type="text" name="OutputFile" id="OutputFile" value="<%=Server.HTMLEncode(objMapSvr.OutputFile)%>">
0
BillPowellAuthor Commented:
Something I should mention to you while Im troubleshooting that might make a difference.  This website uses frames.  The page with the form I mentioned is only one of the frames.  The other thing I should mention is that using the javascript file to embed an object is my workaround for avoiding the extra click required to activate an Active X control.
0
flipzCommented:
I don't think that changes anything but I'm certainly interested in seeing if your theory works - I could make use of the same technique. As long as your embed.js file is in the same frame as the form then all should be fine.
0
BillPowellAuthor Commented:
The embed.js is in the same asp page.  The problem Im having now is that upon generation of the page and while attempting to embed the control, it seems to hang.  Theres no error on the status bar, it just does not appear as it should.

By the way, this is not my theory.  Its actually a well known technique for bypassing that bug.  I got the idea from another colleage, who has it working in several other sites.  So this should work, except that I probably have something wrong with the way Ive implemented it.
0
flipzCommented:
Looks like the value for the param tag is not being concatenated properly - try this:

document.writeln ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE='" + sACGM + "'> <embed name='AXCGM' src='" + sACGM + "' width='100%' height='100%'> </embed> </object>")
0
BillPowellAuthor Commented:
Thats certainly one issue.  Heres the total contents of my embed.js
I have added an alert to see if we were successful in getting the value from the form.  When I run the code, it doesnt get to the alert, so something goes wrong before then.

var sACGM = document["MapValues"].OutputFile.value;
alert(sACGM);
document.writeln ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE='" + sACGM + "'> <embed name='AXCGM' src='" + sACGM + "' width='100%' height='100%'> </embed> </object>")
0
flipzCommented:
Can you post the outputted value for objMapSvr.OutputFile ?
0
BillPowellAuthor Commented:
Heres a typical example(with url modified).  The actual cgm filename will always be different.

        <object id="AXCGM" classid="clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7" width="1020" height="790" viewastext>
          <param NAME="FileName" VALUE="http://mapping.mysite.ca//MapCache/{A04CCAC7-1303-45A5-85A8-1C55A9BE920E}.cgm">
          <embed name="AXCGM" src="http://mapping.mysite.ca//MapCache/{A04CCAC7-1303-45A5-85A8-1C55A9BE920E}.cgm" width="1020" height="790"></embed>
        </object>
0
flipzCommented:
This appears to work for me - try:

<form NAME="MapValues" ID="MapValues" action="GenerateMap.asp" target="frmHid" method=post>
<input type="text" name="OutputFile" id="OutputFile" value="http://mapping.mysite.ca//MapCache/{A04CCAC7-1303-45A5-85A8-1C55A9BE920E}.cgm">
</form>

<script language="JavaScript">
var sACGM = document["MapValues"].OutputFile.value;
alert(sACGM);
document.writeln ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE='" + sACGM + "'> <embed name='AXCGM' src='" + sACGM + "' width='100%' height='100%'> </embed> </object>")
</script>
0
BillPowellAuthor Commented:
Thanks for your help so far, I think Im quite close to getting it to work.  Could you tell me how I should change the first line of the embed.js file, if I needed to get the value this way instead:

'instead of this
var sACGM = document["MapValues"].OutputFile.value;

'I would need to retrieved from an asp request object
var sACGM = <%=Request.Form("OutputFile")%>
0
flipzCommented:
I am not sure if you can do that or not. Since the file you are trying to retrieve this value in is a .js file - I'm not sure if the ASP engine will try to process it - it might but I'm not sure. You can try your suggestion but you'll need to put quotes around it:

var sACGM = "<%=Request.Form("OutputFile")%>";

If possible you can always put the javascript in a script tag in your ASP page instead but then you lose some of the 'reuseability' of the code. Let me know how it goes.
0
BillPowellAuthor Commented:
No problem, I will try to get this to work putting the javascript tag right in the page just to see if it works.  Is this the correct syntax to do that.

var sACGM = "<%=Request.Form("OutputFile")%>";
0
flipzCommented:
Looks good to me - as long as there are no double quotes in the Request.Form("OutputFile") value.
0
BillPowellAuthor Commented:
Were very close now.  The embed.js file is working and getting right variable.  I placed an alert(sACGM); before the last line and confirmed the value in the message box is correct.  So there can only be something syntactically wrong with this last line of the script file:

document.writeln ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE='" + sACGM + "'> <embed name='AXCGM' src='" + sACGM + "' width='100%' height='100%'> </embed> </object>")
0
flipzCommented:
Can you verify that the src file path is valid? If you actually hardcode the object tag with the proper src - does it render properly?
0
BillPowellAuthor Commented:
Yes, the source is valid.
0
flipzCommented:
Put the output to a message box and see if it looks right:

alert ("<object id='AXCGM' classid='clsid:F5D98C43-DB16-11CF-8ECA-0000C0FD59C7' width='100%' height='100%' viewastext> <param NAME='FileName' VALUE='" + sACGM + "'> <embed name='AXCGM' src='" + sACGM + "' width='100%' height='100%'> </embed> </object>");

Just noticed something as well - there was no semi-colon on the end of the last line - I think JS is picky in that regards - either you always use them or you don't - no in between!! Try adding the semi-colon to see if it makes any difference.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BillPowellAuthor Commented:
After several more troubleshooting steps I finally got it to work.
Thanks for your help :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.