Solved

javascript question

Posted on 2016-09-26
6
50 Views
Last Modified: 2016-10-20
Below code work on http web site but it doesn't work on https web site?

I want to use it on https site?
which part of the code I should modify?

<script language="javascript" type="text/javascript">
      function updateData(v)
      {
        var value=v.options[v.selectedIndex].value;
        $("#number").empty(); //empty "digit" drop down box
        if (value!="") //Ensure no empty value is submitted to server side
        {
          jQuery.post("getResult.php","type="+value,updateNumber);
        }
      }
      function updateNumber(data)
      {
        var numberData=jQuery.trim(data).split("\n");//split server side response by "\n"
        var number=document.getElementById("number");
        for (i=0;i<numberData.length;i++)
        {
          value=numberData[i].split("-")[0];//get value from server response
          text=numberData[i].split("-")[1]; //get text from server response
          option=new Option(text,value);    //for better IE compatibility
          number.options[i]=option;         //
        }
      }
    </script>
0
Comment
Question by:Braveheartli
  • 3
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
DPatel earned 500 total points
ID: 41817235
You can use like below :

<script type="text/javascript">
  var protocol = (
      ("https:" == document.location.protocol) 
      ? "https" 
      : "http"
  );
  document.write(
      unescape(
          "%3Cscript"
              + " src='"
                  + protocol 
                  + "://"
                  + "your.domain.tld"
                  + "/your/script.js"
              + "'"
              + " type='text/javascript'
          + "%3E"
          + "%3C/script%3E"
      ) // this HAS to be escaped, otherwise it would 
        // close the actual (not injected) <script> element
  );
</script>

Open in new window

0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 41817239
are you manage to debug in your web browser and check which part is not working?

for example, if you're using  FireFox, try press Ctrl + Shift + Q to inspecting.
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 41817243
Dear D Patel,
I think "  or ' is missing,  ( quote or double quote is missing in the code )
could you please check that?
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 1

Author Comment

by:Braveheartli
ID: 41817249
Dear D Patel,
I'm sorry it didn't work.
+ " type='text/javascript' at the 20. line one double quote was missing,
I run the code, but it didn't work anyway
0
 
LVL 6

Expert Comment

by:DPatel
ID: 41817263
Replace that code with the below :

<script type="text/javascript" language="javascript">
    var fileref=document.createElement('script');
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", document.location.protocol + '//www.mydomain.com/script.js');
    document.getElementsByTagName("head")[0].appendChild(fileref);
</script>

Open in new window

0
 
LVL 1

Author Comment

by:Braveheartli
ID: 41817273
Dear D Patel,
I change the www.mydomain.com/script.js to my actual link,
but it didn't work anyway :(
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript Case Expression 7 29
Html5 Index on a table 7 27
How can I implement a "Select All" with this configuration...? 6 42
where is team.js? 3 26
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question