The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Get value of SLX lookup in javascript function
Posted: 16 Apr 09 8:32 AM
|
I need to get the accountid from a SLX account lookup in a javascript function. I have tried several things along the lines of:
accid=document.getElementById('ctl00_MainContent_InsertOpportunity_lueAccount_Text').value; or accid=document.getElementById('ctl00_MainContent_InsertOpportunity_lueAccount').value; or accid=document.getElementById('ctl00_MainContent_InsertOpportunity_lueAccount').text;
None of them work. Is this possible to do? |
|
|
|
Re: Get value of SLX lookup in javascript function
Posted: 16 Apr 09 11:36 AM
|
This will get you the Text on the field: Account =document.getElementById('ctl00_MainContent_InsertOpportunity_lueAccount_LookupText').value (I have used this one)
This will get you the ID: accid=document.getElementById('ctl00_MainContent_InsertOpportunity_lueAccount_LookupResult').value (I believe this is it based on the Control Script)
So, if you were creating this javascript dynamically it would look as follows: string jscr = "var Account =document.getElementById('" + lueAccount.ClientID + "_LookupText').value; "; jscr += "accid=document.getElementById('" + lueAccount.ClientID + "_LookupResult').value;";
This is from the Control's java script: this.LookupTextId = clientId + "_LookupText"; this.LookupResultId = clientId + "_LookupResult";
|
|
|
| |
|
Re: Get value of SLX lookup in javascript function
Posted: 16 Apr 09 2:40 PM
|
Glad to be able to help.
I have been playing around with the Reflection tool for quite a while and learned a few tricks like this.
I had a page that was developed by a .NET developer and in order to complete Inputing a new Contact, the page had to post 15 times to the server. I had to get away from .NET and do a lot of the UI validation/processing on the client via Javascript ...... In the end, the user has a single post to complete the page. |
|
|
|
Re: Get value of SLX lookup in javascript function
Posted: 17 Apr 09 8:15 AM
|
Yes I did the same thing on the insert contact page Raul, I only had 12 postbacks though so you were beating me!! A handy tip if you want to fire JUST a javascript onchange of a picklist (with no wait for a postback):
// Stringbuilder sb = new Stringbuilder(); // sb.Append(@"var f = document.getElementById('ctl00_MainContent_InsertContact_pklAccAddressState_Text');" + Environment.NewLine); // sb.Append("if(f){ f.attachEvent(\"onchange\", makeEventFunc(document.all.ctl00_MainContent_InsertContact_pklAccAddressState_Text));}" + Environment.NewLine); //makeventfunc is a jscript placeholder function that I am using to pass parameters to. You cant pass parameters by default on an attachEvent // OR // sb.Append("if(f){ f.onchange = myfunction;}" + Environment.NewLine);
// ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "JSCR", sb.ToString(), true);
You basically attach an onchange event for the textbox part of the SLX Picklist Control (Controls[0] in the collection I believe). It may also be possible to do this in C# similar to the following:
((TextBox)pklAccAddressState.Controls[0]).Attributes.Add("onchange","myJSFunction()");
I haven't tested that though (I used the method above that), just a theory..
Obviously, ensure the JScript function you are calling is on the page, using RegisterClientScriptBlock as opposed to RegisterStartupScript..
This is a bit IE specific (all I require for the particular customer) but you can make it work in other browsers with a quick check - I think its addEventListener for Firefox et al.
I have found many uses for this approach so hopefully somebody will find it useful - posting back ALL the time just seems wrong to me! And Im not sure if its just my server/browser setup but there is a slight delay that I didnt experience when using the (very) lightweight Ajax I used to employ in 6.2.
Rant over  |
|
|
|
Re: Get value of SLX lookup in javascript function
Posted: 17 Apr 09 9:33 AM
|
Thanks.
I actually ended up creating my own Control for Picklists because I have had to give Web Users the ability to Add/Remove custom Picklist items (same as in the Windows Client). |
|
|
|
Re: Get value of SLX lookup in javascript function
Posted: 17 Apr 09 9:42 AM
|
Originally posted by Nick Hollis
I have found many uses for this approach so hopefully somebody will find it useful - posting back ALL the time just seems wrong to me! And Im not sure if its just my server/browser setup but there is a slight delay that I didnt experience when using the (very) lightweight Ajax I used to employ in 6.2.
Rant over  |
|
I agree completely. Posting back all of the time is wrong. Specially on forms that are built mainly for Data Entry (Insert Forms) because the users typically want to Input the data quite fast.
I have seen many users not realize that the form was posting while they were still typing and then complain about it and about the process taking a long time to complete. And I can't but agree.
Now, on the other end, and not sure if any one of you had ran into this yet, I had javascript that was registered as a Client block and that executed on load of the page. However, if the user clicked on certain buttons (lets say the Edit button for the Contact Name Control) the execution of the startup script failed.
This off course would cause other issues later on, so I ended up having to Block the UI by utilizing a quick IFRAME (running on IE), thus avoiding user Input until all the page was fully initialized. |
|
|
|
Re: Get value of SLX lookup in javascript function
Posted: 17 Apr 09 9:52 AM
|
Originally posted by Raul A. Chavez
Now, on the other end, and not sure if any one of you had ran into this yet, I had javascript that was registered as a Client block and that executed on load of the page. However, if the user clicked on certain buttons (lets say the Edit button for the Contact Name Control) the execution of the startup script failed.
This off course would cause other issues later on, so I ended up having to Block the UI by utilizing a quick IFRAME (running on IE), thus avoiding user Input until all the page was fully initialized. |
|
Could you please expand on this? Did you have a ScriptManager RegisterStartUpScript, then calling your code you added through add ClientScriptBlock? If so are you also saying if the user clicked the Edit button BEFORE the screen had initialised properly (all of the Task Pane, Group Navigator generation and record placement etc.) or just anytime when they clicked it? Thanks |
|
|
|