This topic is locked

Jquery wildcard match - easily field reference even in popup JS forms

7/25/2011 12:48:16 PM
PHPRunner Tips and Tricks
F
FunkDaddy author

I'm Using PHPR 5.3 (build 7474)... ever since introduction of add/edit/view popup forms field ID's are generated dynamically each time form is open... therefore we can no longer rely on standard JS notation sucn as "document.getElementById(fieldname').value;" etc. Instead we are now supposed to use the JS API as per the PHPR online manual (http://xlinesoft.com/phprunner/docs/javascript_api.htm), that takes care of the problem. HOWEVER... I noticed that the JS API does not work inside the "custom button" button feature of PHPR (Client Before, OnServer, Client After).
While it is possible to declare global JS variables via the JS Onload event of certain popup forms, then reuse them inside the "custom button", we nonetheless run into problems when trying to set value on field forms from that button if the for is a popup. The issue is that we can't refer to the field ID because they can change due to the dynamic nature of the poupup form (ex: value_Discount_Amount_4, then next time opened it's value_Discount_Amount_6, etc).
You can't use the JS API to refer to the field value; "Ex: var ctrl_Discount_Amount= Runner.getControl(pageid, 'Discount_Amount');".
Thus, if you need to call the field (to set value, get value, etc) you can simply use JQuery wildcar matching to find the ID of the field you want to refer to.
For example, in this case I did the following:



//Note the asterisk '*' at the beginning of the selector matches all elements.

$('*[id*=Discount_Amount]').val(result["Discount_Amount"]);


I have to give credit where its due...I found this solution from an answer posted here http://stackoverflow.com/questions/1206739/jquery-wildcard-search
By the way... if you run into postings like this: http://ropox.net/archives/1081 just know the //S* will not work!
Cheers,

C
cgphp 7/25/2011

This, instead, selects all elements with an id starting with "value_Discount_Amount":

$("*[id^='value_Discount_Amount']")