Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating a variable to use in Javascript

Engaged ,
Nov 04, 2010 Nov 04, 2010

I have created a web site with a search function where the user can use drop down menus. This is in a small window that pops up when you click Advanced Search. They choose the first drop down and then the next drop down appears and has items in it depending on what was chosen in the first drop down. This all works, except that it only works on our www. site. If you don't type in the www., then these drop down menus do not work. These drop downs use Javascript and in this javascript, I have the full path of our web site to the .cfm file where this is more javascript for the drop downs. This path has the www. in it. Does anyone know how I can write this so that both ways or paths work- with and without the www.? Do I need to set up some kind of variable to use? How do I do that in Javascript. I think I can do it in Cold Fusion, but I don't think that will work inside the javascript. The web site is www.ironwoodelectronics.com  Here is the javascript code below. Thanks.

Andy

<script>
     function getICNumber() {
          $('#ICNumber').load("http://www.ironwoodelectronics.com/incICNumber.cfm",{ManufacturerID:$('#select_ManufacturerID').val()});
     }
     function getPackage() {
          $('#Package').load("http://www.ironwoodelectronics.com/incPackage.cfm",{ManufacturerID:$('#select_ManufacturerID').val(),ICNumber:$('#select_IC_Number').val()});
     }
     
     function getPackageType() {
          $('#PackageType').load("http://www.ironwoodelectronics.com/incPackageType.cfm",{FunctionID:$('#select_FunctionID').val()});
          $('#Pitch').html("");
     }
     function getPitch() {
          $('#Pitch').load("http://www.ironwoodelectronics.com/incPitch.cfm",{FunctionID:$('#select_FunctionID').val(),PackageID:$('#select_PackageID').val()});
     }
     function getBody() {
          $('#Pitch').load("http://www.ironwoodelectronics.com/incPitch.cfm",{FunctionID:$('#select_FunctionID').val(),PackageID:$('#select_PackageID').val(),PitchID:$('#select_PitchID').val()});
     }
     function getArray() {
          $('#Pitch').load("http://www.ironwoodelectronics.com/incPitch.cfm",{FunctionID:$('#select_FunctionID').val(),PackageID:$('#select_PackageID').val(),PitchID:$('#select_PitchID').val(),BodyID:$('#select_BodyID').val()});
     }
</script>
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 04, 2010 Nov 04, 2010

You have two errors.

First, you need to escape any hash characters (#) that are within CFOUTPUT that aren't used to output CF variables. You escape them by doubling them:

$('#ICNumber').load

should be

$('##ICNumber').load

Second, CGI.HTTP_HOST only contains the host, not the protocol, etc. So, you need to do something like this:

$('##ICNumber').load("http://#cgi.http_host#"/...")

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned

...
Translate
LEGEND ,
Nov 04, 2010 Nov 04, 2010

At what point does it stop working?

Does the advanced search use window.open or href target="_blank"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 04, 2010 Nov 04, 2010

The window opens up just fine. When the drop downs are displayed in this window, only one shows up at first. There are supposed to be

2 that show up from the beginning. When I choose something out of the first one, the 2nd one does not show up at all.

The advanced search link uses the onclick or show/hide function in Dreamweaver. It's not the window.open or href target="_blank". This is not the problem though because on the www. site it works and on the one without the www. it does not work. We do not want to re-direct the one without the www. to the www. one. That's why I'm trying to figure out how to do it within the javascript code instead.

Andy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 04, 2010 Nov 04, 2010

I've never had to solve this.  But www.somesite.com and somesite.com are technically two different domains (or subdomains) and your posting brings to mind what I have read about the crossdomain document that is used by these features to try and prevent and control cross domain attacks.  You may need to do something with the crossdomain.xml document that I believe controls all of this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2010 Nov 04, 2010

I don't know exactly what the load method is doing there, but you may be able to simply use relative or site-root-relative paths:

If not, you can just identify the request host using the CGI variable (I think it's CGI.HTTP_HOST) and use that instead of the hard-coded value for the host name.

$('#ICNumber').load("incICNumber.cfm", ...

or


$('#ICNumber').load("/incICNumber.cfm", ...

If not, you can just identify the request host using the CGI variable (I think it's CGI.HTTP_HOST) and use that instead of the hard-coded value for the host name.

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

GSA Schedule, and provides the highest caliber vendor-authorized

instruction at our training centers, online, or onsite.

Read this before you post:

http://forums.adobe.com/thread/607238

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 04, 2010 Nov 04, 2010

How do I write the code for CGI.HTTP_HOST? Is it like this:

.load("CGI.HTTP_HOST/incICNumber.cfm"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 04, 2010 Nov 04, 2010

jamie61880 wrote:

How do I write the code for CGI.HTTP_HOST? Is it like this:

.load("CGI.HTTP_HOST/incICNumber.cfm"

Well, it's a variable so you would want to dereference it.

.load("#cgi.http_host#/inclCNumber.cfm").

Then ColdFusion will determine the value of cgi.httphost, subsitute it where the variable is located and send the concatinated string to the browser.

Message was edited by: ilssac: Don't forget you will need a <cfoutput></cfoutput> block around any output that includes variables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 04, 2010 Nov 04, 2010

I tried this, but this did not work. It said something about the  complier was not correct or something. I put the cfoutput tags around  the whole javascript tag. Was I not supposed to do that? How else do I  write it? Below is what I tried. Do I not need the quotes? There are  other # symbols in the javascript that could be causing the problem too  like the #ICNumber or #Package, etc.

<cfoutput>

<script>
     function getICNumber() {
          $('#ICNumber').load("#cgi.http_host#/incICNumber.cfm",{ManufacturerID:$('#select_ManufacturerID').val()});
     }
     function getPackage() {
          $('#Package').load("#cgi.http_host#/incPackage.cfm",{ManufacturerID:$('#select_ManufacturerID').val(),ICNumber:$('#select_IC_Number').val()});
     }
     
     function getPackageType() {
          $('#PackageType').load("#cgi.http_host#/incPackageType.cfm",{FunctionID:$('#select_FunctionID').val()});
          $('#Pitch').html("");
     }
     function getPitch() {
          $('#Pitch').load("#cgi.http_host#/incPitch.cfm",{FunctionID:$('#select_FunctionID').val(),PackageID:$('#select_PackageID').val()});
     }
     function getBody() {
          $('#Pitch').load("#cgi.http_host#/incPitch.cfm",{FunctionID:$('#select_FunctionID').val(),PackageID:$('#select_PackageID').val(),PitchID:$('#select_PitchID').val()});
     }
     function getArray() {
          $('#Pitch').load("#cgi.http_host#/incPitch.cfm",{FunctionID:$('#select_FunctionID').val(),PackageID:$('#select_PackageID').val(),PitchID:$('#select_PitchID').val(),BodyID:$('#select_BodyID').val()});
     }
</script>

</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 04, 2010 Nov 04, 2010

Yes, putting the <cfoutput> block around the entire <script> block is fine.

This is a CFML page, right not a .htm|.html|.js or some other file extension that is not processed by ColdFusion?

Did you "view source" in the browser to see if and how the variable was rendered and if it is the expected results.

You did confirm that cgi.http_host is the right variable?  As Dave was originally guessing and I just assumed he was right and|or you had checked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 04, 2010 Nov 04, 2010

Yes, this is a .cfm page. I have this code on a template page in Dreamweaver and then when I save it, it just updates the pages based on this template. The only problem I've noticed is that it does not update the relative paths in the javascripts. It only updates it within the other code.

This is the error I get:

ColdFusion was looking at the following text:

\'

The CFML compiler was processing:

  • An expression      that began on line 37, column 20.
    Your expression might be missing an ending "#" (it might look      like #expr ).
  • The body of a      cfoutput tag beginning on line 34, column 2.

  The error occurred in E:\Ironwoodelectronics\index.cfm: line 37

35 : <script>

36 :    function getICNumber() {

37 :            $('#ICNumber').load("#cgi.http_host#/incICNumber.cfm",{ManufacturerID:$('#select_ManufacturerID').val()});

38 :    }

39 :    function getPackage() {

This is what the source shows below when I view source. It looks like it's erroring out at the function getPackage() { for some reason.

$('#ICNumber').load(&quot;#cgi.http_host#/incICNumber.cfm&quot;,{ManufacturerID:$('#select_ManufacturerID').val()});</b>
38 :      }
39 :      function getPackage() {
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2010 Nov 04, 2010

You have two errors.

First, you need to escape any hash characters (#) that are within CFOUTPUT that aren't used to output CF variables. You escape them by doubling them:

$('#ICNumber').load

should be

$('##ICNumber').load

Second, CGI.HTTP_HOST only contains the host, not the protocol, etc. So, you need to do something like this:

$('##ICNumber').load("http://#cgi.http_host#"/...")

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

GSA Schedule, and provides the highest caliber vendor-authorized

instruction at our training centers, online, or onsite.

Read this before you post:

http://forums.adobe.com/thread/607238

Dave Watts, Eidolon LLC
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 04, 2010 Nov 04, 2010
LATEST

Dave,

   Thank you! This finally worked! I kept the quote after the .cfm instead of the cgi.http_host#  Thanks again.

Andy

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources