Solved

javascript question

Posted on 2016-09-26
6
70 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 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 52

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

729 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