0

Hello

I have a combobox which has some values. When I click on it and select a item (with my mouse, for now) I want to get those values. Im not sure if its mousedown or comboboxchange or how its called.

Now Im a completely noob when it comes to events in Javascript so if you could post the "standard" function for it, thats great. From there, I THINK, I can work it out.

Also I use jQuery if it helps out.

4
Contributors
11
Replies
13
Views
4 Years
Discussion Span
Last Post by Taywin
1

By using Jquery , Try this

    $('#CompoBoxId').change(function() {
        alert($(this).val());
    });
0

Tried that code but it gives me a error

SyntaxError: missing : after property id

Also tried:

$j('#dibujoshechos').change(function() {
    alert($j(this).val());
    });    ,

And with double quotes: Nothing. Same error. I remove this code and it works perfectly.

0

What's with the comma at the end of line 3?

More functions follows it

0

Can you show the code before and after as well, I don't believe the comma is supposed to be there (semicolon yes, comma, I don't think so). I could be wrong, but it just doesn't look right and without the context around it, it's hard to say.

Also the error "SyntaxError: missing : after property id" is referring to a property called id, which I don't see in your code example, which tells me there is an error before or after what you have posted.

0

Here is a example:

startListeners: function(){
      this.canvas.mousedown(function(e){
          this.handleCanvasMouseDown(e);
      }.bind(this));
    },


        $j('#combobox').change(function() {
    alert("hi");
    });, 

    handleCanvasMouseDown: function(e){

        this.drawManager.unSelectAllPointsOfTheDrawingThatHasPoints();
    },

With and without the comma in the "});" it fails, giving me that error.

0

Not sure what else to try.....

What would be the standard nonjQuery way? Maybe that will work.

0

I'd suggest learning about creating objects and annonymous functions in JavaScript. It will help you understand how to set this up properly, I don't think it's being done right.

//these seem to be functions for setting up events for something
startListeners: function(){
    this.canvas.mousedown(function(e){
        this.handleCanvasMouseDown(e);
    }.bind(this));
},
handleCanvasMouseDown: function(e){
    this.drawManager.unSelectAllPointsOfTheDrawingThatHasPoints();
},
//without knowing what else your object does I can only guess that this is what you need
setUpComboBox: function(){
    //$j('#combobox').change(function() {
    //    alert("hi");
    //});
    //this probably doesn't need to be in an object, especially if you change it to the following
    $j(document).on('change', '#combobox', function(){
        alert('hi');
    });
},
//any other methods for your object
...
0

What would be the standard nonjQuery way?

Here you are...

<html>
<head>
<script type="text/javascript">
function doSomething(selObj) {
  if (selObj && selObj.tagName=="SELECT") {
    alert("You selected index "+selObj.selectedIndex+" , value: "+selObj.value)
  }
}
</script>
</head>

<body>
<select onchange="doSomething(this)">
  <option value=1>One</option>
  <option value=2>Tow</option>
  <option value=3>Three</option>
  <option value=4>Four</option>
</select>
</body>
</html>

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.