[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript Function querying SQL Recordset in ASP page

Posted on 2004-10-22
2
Medium Priority
?
171 Views
Last Modified: 2010-05-19
I have an asp page with some input boxes. I have an onchange function that is fired on change of the value in the input box. What I want the function to do is take the new value entered in the text box and query it to see if it is in a SQL server table if it is not produce and error message.
0
Comment
Question by:cyberdidj
2 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 1000 total points
ID: 12380884
This cannot be achieved with JavaScript; you'll have to have the form submit itself when the onchange event occurs, so that your ASP can query the database to check the value.
0
 
LVL 8

Assisted Solution

by:sigmacon
sigmacon earned 1000 total points
ID: 12380981
For IE 5.5+, Mozilla-based browsers using 1.3 or higher (e.g. Firefox 0.8+) and Safari 1.3+:

instantiate an XML Request Object:

      try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
            try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                  try {
                        xmlhttp = new XMLHttpRequest();
                  } catch (eE) {
                        alert("Could not create XMLHttpRequest object!\nPlease use a browser that supports this feature.");
                        throw "Could not create XMLHttpRequest object!\nPlease use a browser that supports this feature.";
                  }
            }
      }

if xmlhttp is not null or undefined, you can continue.

get the value from the drop down ( I am assuming you know how to do that), then make a request to your server where you have a file that runs the actual query:

    try {
      xmlhttp.open("GET", "checkvalue.asp?random=" + rand(100000000) + "&valuetocheck=" + valuetocheck, false);
        xmlhttp.send(null);
      if (xmlhttp.responseText == 'value_is_valid') {
            // do something
      } else {
            // show error message
      }
    } catch (e) {
        debugException(e);
    }

this special asp page should not return any html, but text that you can use to determine whether the value was valid or not. The beaty of this is that it does not require a new page reload. The downside is it only works with the latest browsers
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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

834 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