Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Noob Javascript question

Name: Anonymous 2009-04-30 21:25

So I have this script I found for autocomplete forms that runs off of a sql query on keyup. The problem I'm facing is sending the clicked item to the field you type in

function fill(thisValue) {
    $('#inputIdHere').val(thisValue);
    setTimeout("$('#suggestions').hide();", 200);
}

<input type="text" size="30" value="" id="inputIdHere" onkeyup="lookup(this.value, 'query.php');" onblur="fill();" />

mind you this isn't all of it but should be the section causing the problem. I want to either find the id currently 'inputIdHere' or I want to type it as a variable in fill();

but when I type it in fill i break thisValue as far as i can tell

halp?

Name: Anonymous 2009-04-30 21:29

cont.
i break it when if i do something like

>function fill(idname, thisValue){ etc.}

>onblur="fill('inputIdHere');"
its thisFailue fucking me up..

Name: Anonymous 2009-04-30 21:36

Read SICP.

Name: Anonymous 2009-04-30 21:39

I don't really get what you want to do, taking a guess.

$("input#inputIdHere").keyup(function(event) {
    if(event.keyCode == 38) {
        $.get("query.php");
    }
}).blur(function() {
    $(this).val($(this).attr("id"));
    setTimeout(function() {
        $("#suggestions").hide();
    }, 200);
});

Name: Anonymous 2009-04-30 21:43

>>4
Uhh, sorry you might want to remove the "if(event.keyCode..)" bit, I thought you wanted it to fire on the VK_UP (arrow key) press.

Name: Anonymous 2009-04-30 21:47

the fill function is hardcoded to update id="inputString". I want to make that dynamic. Just looking to get the id on demand not predefined.

the full working javascript is
<script type="text/javascript">
    function lookup(inputString, sqlquery) {
        if(inputString.length == 0) {
            // Hide the suggestion box.
            $('#suggestions').hide();
        } else {
            $.post(sqlquery, {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                }
            });
        }
    } // lookup
   
    function fill(thisValue) {
        $('#inputString').val(thisValue);
        setTimeout("$('#suggestions').hide();", 200);
    }
</script>

html is the same
<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value, 'query.php');" onblur="fill();" />

Name: Anonymous 2009-04-30 21:50

And here is my interpretation of what you actually want to do but failed to explain. Which sends a query, stores the result in sqlResult- and then writes that result to the input box onblur.

<html>
    <head>
        <script>
            $(document).ready(function() {
                var sqlResult = null;
                $("input#inputIdHere").keyup(function(event) {
                    $.get("query.php",{param: $(this).val(), type: "sql", language: "en"},function(data) {
                        sqlResult = data;
                    })
                }).blur(function() {
                    $(this).val(sqlResult==null?"":sqlResult);
                    sqlResult==null;
                    setTimeout(function() {
                        $("#suggestions").hide();
                    }, 200);
                });
            });
        </script>
    <head>
    <body>
        <input type="text" size="30" value="" id="inputIdHere" />
    </body>
</html>

Name: Anonymous 2009-04-30 21:56

Just state the entire problem and I'll make you somthing better, you are clearly too stupid to be able subclass the problem areas and spoonfeed those.

Name: Anonymous 2009-04-30 22:01

DON'T HELP HIM!!!

Name: Anonymous 2009-04-30 22:02

>>8
what part of 'getting the id of the input' is hard to understand.

everything works fine how it is but i want to get 'this.goddamn.id'

its just one problem = how do i get input ids without declaring them by hand in the function.

Name: Anonymous 2009-04-30 22:09

>>10
I've already shown you, don't fucking use onblur, onkeyup etc bullshit, jquery has its own for a reason. I'm presume you want the same behavior for multiple inputs which is why you need to be able to see which input to modify. Use something like
$("input.customClassName").blur(function() {
    $(this).val("PENIXEN");
});


Then you can just give each input you want to have this onblur effect the class "customClassName".

>>9
The faster I help him the faster he will fuck off.

Name: Anonymous 2009-04-30 22:13

>>11
I appreciate the help. I will dick around with this stuff and see what I get (ie i'm fucking off)

Subject is 'noob' for a reason.

Name: Anonymous 2009-05-01 2:53

>>12 considered harmful and DQN

Name: Anonymous 2009-05-01 5:37

>>9
hahaha diregard that I suck cocks

Name: Anonymous 2011-02-04 16:52

Don't change these.
Name: Email:
Entire Thread Thread List