HOW TO access fields in Add/Edit Modes using JavaScript?

Talk and info about common issues

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

administrator
Site Admin
Site Admin
Posts: 5988
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO access fields in Add/Edit Modes using JavaScript?

Postby administrator » Mar 8th, '12, 15:25

Each element in Add/Edit mode may be easily accessed with JavaScript methods.
Each element gets an ID an a name that consists from "req_type" and field name.

For example:

Code: Select all

"comment" => array(..., "req_type"=>"rt",... )


will be created as:

Code: Select all

<input type="text"  id="rtycomments" name="rtycomments" .....>....</textarea>


So, to access this element, you may use a following code:

Code: Select all

<script>
     var val = document.getElementById("rtycomments").value;
     alert(val);
</script>


TIP: you may quickly check the element ID by opening a Page Source in your browser.
For Firefox: Tools -> Web Developer -> Page Source
For Chrome: Tools -> View Source
For IE: View -> Source

Return to “ApPHP DataGrid {HOW TO}”