?
Solved

javascript question

Posted on 2016-09-26
6
Medium Priority
?
83 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

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

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 7

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
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…
Suggested Courses

801 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