Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:33:41+00:00 2026-05-31T12:33:41+00:00

This is the Javascript Function. Please Explain How to compare two string in Javascript.

  • 0

This is the Javascript Function. Please Explain How to compare two string in Javascript.

   <head>
    <script type="text/javascript">
/*javascript function*/ 
    function ajax(str)
    {
    if (str.length==0)
      {
      document.getElementById("res").innerHTML="";    
      return;
      }
      if(str=="Select City")
      {
      alert("Please Select a City");
      }
    document.getElementById("res").innerHTML=="";
    var url="code1.php?q="+str+"&r"+Math.random();
    var obj;
    try{
    obj=new ActiveXObject(Microsoft.XMLHTTP);
    }
    catch(e)
    {
        try
        {
        obj=new XMLHttpRequest();
        }
        catch(e)
        {
        alert("Your browser not suport ajax");
        }
    }
    obj.open('Get',url,true);
    obj.send(null);
    obj.onreadystatechange=function()
    {
    if(obj.readyState==4)
    {
    document.getElementById("res").innerHTML=obj.responseText;
    }
    }
    }
    </script>
    </head>

    <body>

    <select onchange="ajax(this.value)" name="sel" id="btn"><option>Dharmashala</option><option>Manali</option><option>Shimla</option></select>
    <div id="res"></div>
    </body>
    </html>

But it does not work please suggest me a proper method to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:33:42+00:00Added an answer on May 31, 2026 at 12:33 pm

    I’m pretty sure it’s not working because you have your this context incorrect. this.value is trying to call the value of your select element instead of the selected option. Try this:

    window.addEventListener('load', function(){
      var select = document.getElementById('btn');
      var selected = select.options[select.selectedIndex].value;
    }, false);
    window.addEventListener('change', function(selected) { changeHandler(selected); }, false);
    
    function changeHandler(selected) {
      // run your ajax() function
    }
    

    Also, be sure to put a value on each of your option elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript function: <script type=text/javascript> function quickCardRegister_OnCompleteSave() { publishContent('This is a
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
Can someone please explain the structure of this line of a script for me?
Who can explain this, please? In my function, I use .remove() to remove one
Could someone please explain the significance of prototype.init function in JavaScript and when it
I came across this JavaScript function and I don't understand quite what it's doing,
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
As you may know, when we have this code in Javascript : function getName()
I'm using a javascript function to submit my form. This works in every browser
I have a JavaScript function, pop_item . I have to call this from PHP,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.