-1

Following is the code:

<td><bean:write name="row" property="suppnr" /></td>

How to get the supplier number (suppnr) value like below?

var sup = document.getElementByID('suppnr').value(); // This dosent work as suppnr is a property 
alert(sup);

Do we have any method to do this? Kindly help

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Padmaja
  • 111
  • 1
  • 11

3 Answers3

1

Select elements where attribute property exists:

var suppnr = $('[property]');

Select elements where attribute property equals to suppnr:

var suppnr = $('[property="suppnr"]');

alert (suppnr.attr('name'));
NoSkill
  • 718
  • 5
  • 15
0

First of all, you don't have ID on tr, so first add id attribute as you are selecting via the id attribute.

<td><bean:write name="row" id="suppnr" property="suppnr" /></td>

Then you can easily get any attribute using getAttribute function:

var sup = document.getElementById('suppnr').getAttribute('property'); 
alert(sup);
Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28
0

Some properties are reflections of attributes, which means that setting the property sets the attribute, which allows you to use attribute selectors. For instance, an input element's defaultValue property is a reflection of its value attribute (which its value property is not).

Otherwise, you select by what you can and use filter to filter the resulting list to only the elements you actually want.

For example, I'd set a property using jQuery like this:

$('#foo').prop('my-property', 'value');

No, there's no way to select by that property directly, you'd need something like my filter suggestion above:

var list = $("something-that-gets-you-close").filter(function() {
    return this["my-property"] == "value";
});

You might consider using data-* attributes instead:

$("#foo").attr("data-my-property", "value");

then

var list = $("[data-my-property='value']");

to select it (the inner quotes are optional for values matching the definition of a CSS identifier). Note that attribute values are always strings.

Beware: There's a persistent misconception that jQuery's data function is a simple accessor for data-* attributes. It is not. It manages a data cache associated with the element by jQuery, which is initialized from data-* attributes but disconnected from them. In particular, .data("my-property", "value") would not let you find that later via a [data-my-property=value] selector.

shruti
  • 56
  • 6