views:

433

answers:

3

hi All, I have a problem that i want to access the normaltagCmt elements value:

<div id="random no">
  <div id="normaltagdialog">
  <table style="width:100%; height:100%" border="2px">
    <tr style="width:100%; height:13%" align="left">
      <td>
        <label> {$LANG.TEXT}</label>
      </td>
    </tr>
    <tr style="width:100%; height:59%; vertical-align:middle" align="center" >
      <td>
        <textarea id="normaltagCmt" style="width:90%; height:90%" ></textarea>
      </td>
    </tr>
    <tr style="width:100%; height:13%">
      <td>
        <label> {$LANG.COLOR}</label>
      </td>
    </tr>
    <tr style="width:100%; height:15%; "> 
      <td>
        <table style="width:100%;height:100%"  cellpadding="2" cellspacing="2">
          <tr id="colorPad" align="center">
          </tr>
        </table>
      </td>
    </tr>
  </table>
</div>
</div>

The script i have written above is a jquery dialog and this dialog opens many times. i want to get the value of normaltagCmt for a particular div with a specific random id. How can i get that in javascript?

A: 

Try $('#random_no #normaltagCmt').val().

Bavo
A: 

i hope by "random no" you mean random number, you cant have a space in a ID and ill use ID14 instead of "random no".

$("#ID14 #normaltagdialog table tr td #normaltagCmt").val()
Petoj
A: 

There can only be one of any ID in javascript, so you could just do $('#normaltagCmt') and it will always only return the one element.

However, if you want to check to make sure that it is a child of an element with a random id (a number that you do not know), then it will get a little trickier.

$("#normaltagCmt").filter(function() {
    var valid_parent = false;
    var numeric_re = /^\d+$/g;
    for( var parent in $(this).parents("div") ) {
        if( re.test(this.id) ) {
          valid_parent = true;
          break;
        }
    }
    return valid_parent;
}

This bit of jQuery will test to make sure that the element with the specified id has a parent div with a numeric id. If it does not, then you will be left with an empty jQuery object.

geowa4