#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Suchfunktion mit JAVA programmieren


    Hallo!!! Hätte da eine Frage...ich würde gerne einen Wert in eine Textbox eingeben sodass ich letztendlich in der zweiten Textbox als Ausgabe den gewünschten Suchtext in voller Länge erhalte...das ganze sollte mit Java und NICHT mit PHP programmiert werden...hab da schon eine Idee gehabt die aber leider bis jetzt noch nicht gefruchtet hat(Wird /Hello/g eingegeben kommt "Ihre Suche wurde leider in unserer Datenbank nicht gefunden"! und nicht so wie Erwünscht /Hello/g(wenn möglich weiß vielleicht jemand wie man dass /und/g bei Hello wegzaubern könnte???)). Vielen Danke schon mal im Vorraus
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0
    <div method="get" id="FunktionANTWORT">
    <input id="Name" />
    <input id="Name1" >
    </div>



    <script type="text/javascript">
    var FunktionANTWORT = document.getElementById('FunktionANTWORT');
    FunktionANTWORT.onkeyup = function() {
    var Sucheingabe = document.getElementById('Name').value;
    var Suche =/Hello/g;
    var Suchausgabe = document.getElementById('Name1');

    if (Suchausgabe==Suche.test(Sucheingabe)) {
    Suchausgabe.value = Suche;
    } else {
    Suchausgabe.value = "Ihre Suche wurde leider in unserer Datenbank nicht gefunden";
    }
    return false;
    }
    </script>
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    this is an English board (as you may have noticed).

    First of all: JavaScript is not Java. Those two completely distinct languages which have nothing in common except the first four characters of their name (and some basic technical concepts). "Java is to JavaScript as ham is to hamster".

    You seem to have trouble using regexes. Actually, regexes aren't appropriate in your case, because you're looking for a constant string. What you want is String.indexOf().

    If you do wanna use regexes (for whatever reason), you need to repair several things. Check this:

    Code:
    var Suchausgabe = document.getElementById('Name1');
    
    if (Suchausgabe==Suche.test(Sucheingabe)) { ...
    What is this supposed to do? Suchausgabe is a DOM object. And Suche.test() yields either true or false. How do you compare a DOM object with a boolean? This makes no sense.

    If guess you meant this:

    Code:
    if (Suche.test(Sucheingabe)) { ...
    Apart from that, the "g" modifier in your regex makes no sense, because this forces the regex to find all matches rather than stopping at the first match (which is what you want). And last but not least, the RegExp.test() method returns a boolean, which is why comparing it with
    Last edited by Jacques1; July 31st, 2013 at 08:23 AM.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0
    Thank you for your reply ... the formula now works as expected ... sorry I have not replied in English ... I'm not very experienced in javascript ... if it is possible I beg you to help me a second time with the following problem ... I'd like to get the response:

    (output)the answer should be wolfgang
    for the input wolfgang(all letters in lowercase!!!).

    In order to do soo I put in a replace formula... Thanks again for everything !

    here is the formula:

    <div method="get" id="FunktionANTWORT222222">
    <input id="Name111111" size="130">
    <input id="Name222222" size="130">
    </div>
    </div>
    <script type="text/javascript">
    var FunktionANTWORT222222 = document.getElementById('FunktionANTWORT222222');
    FunktionANTWORT222222.onkeyup = function() {
    var xbbbbbb = document.getElementById('Name111111').value;
    var zbbbbbb = document.getElementById('Name222222');

    if (xbbbbbb==("Wolfgang")) {
    zbbbbbb.value = xbbbbbb.toLowerCase().replace(/[.*+?|()[\]{}\-]/gi,"").replace (/^\s+/, '').replace (/\s+$/, '').replace(/(\s)\s+/g,"$1");
    } else {
    zbbbbbb.value = "2";
    }
    return false;
    }
    </script>

IMN logo majestic logo threadwatch logo seochat tools logo