开发者

JQuery - Find value of a dynamic ID

OK so I'm using a CRM on demand system, and a URL needs to be updated when a form is updated. The form cannot be referenced by ID for some reason so I need another way of getting the va开发者_如何学编程lue="THIS" out of it.

No Ids allowed! (Unless you know why) Thanks :)

The HTML concerned:

<input id="ServiceRequestEditForm.CustomObject6 Id" class="inputControlFlexWidth" type="text" value="THIS CHANGES AFTER UPDATE" tabindex="9" size="25" name="ServiceRequestEditForm.CustomObject6 Name">

Thanks for the quick answers. The reason I couldn't select an ID was because it contained a fullstop. E.g. EditForm.CustomObject6 needs to become EditForm\.CustomObject6

The answers are still very useful however.


You can use custom attributes.

<script>
    var value = $("input[custom=custom]").attr("value");
</script>
<input custom="CUSTOM" id="your thing" class"blah blah" type="text" value="VALUE" tabindex="9" size="25" name="blah blah">


<input id="blah" onchange="javascript: MyOnChange(this);">

<script>
function MyOnChange(myControl)
{
    alert(myControl.id);
} 
</script>


ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

No spaces allowed, your ID is not valid.


If the only problem is the . in the ID, then you can do something like:

var field = $("input[id='full.ID.here']");

.

If the ID contains some dynamic parts that always changes, but one part of it is constant:

var field = $("input[id*='ID part here']");

Note the *=.

.

If the known part of the ID is particularly at the end of it, you can use:

var field = $("input[id$='ID part here']");

Note the $=.

.

For a full reference of jQuery selectors, check:

http://api.jquery.com/category/selectors/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜