I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.

Recommended Answers

All 3 Replies

I assume you are after JavaScript, not Java. Anyway with JavaScript values are not strongly typed, so if the values are numbers, you can use "+".

I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.

casting it to an Integer. but from your question I take it you want an int, and not an Integer.
so, cast it to a String, and parse that to an int.

for instance, you get back an Object with value = "6";

public int objectToInt(Object givenObject){
  String inString = (String)givenObject;
  return Integer.parseInt(inString);
}

't voila, instant integer-value. this will only work if the value stored in the object is a valid integer value, so if you have any other data in that list, you may want to catch possible exceptions.

If you added the items as Integer objects:

int selectedValue = ((Integer)comboBox.getSelectedItem()).intValue();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.