Solved

javascript question

Posted on 2016-09-26
6
36 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 5

Accepted Solution

by:
D Patel 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 49

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 5

Expert Comment

by:D Patel
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now