Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...How can one use JavaScript to find a DNN element with dynamic ID on it?How can one use JavaScript to find a DNN element with dynamic ID on it?
Previous
 
Next
New Post
6/6/2018 5:58 PM
 

Dear DotNetNuke Developers,

Please help.

I need a quick JavaScript hack.

It is for this page...

C:\inetpub\wwwroot\dotnetnuke\DesktopModules\Admin\Security\Register.ascx

...and I need to find this control...

< input name="dnn$ctr$Register$userForm$86b49818327acdade9bdf39f7f0d595e$86b49818327acdade9bdf39f7f0d595e_TextBox" type="text" id="dnn_ctr_Register_userForm_86b49818327acdade9bdf39f7f0d595e_86b49818327acdade9bdf39f7f0d595e_TextBox" >

...and I just want to put a quick hack into the ASCX itself, in JavaScript, and Yes I know it would be blown away if I upgrade, but I am on DotNetNuke 8.0.3 now and I am stuck on that version for a while, so I just need a quick hack...

...but....

...the control ID is generated dynamically with each load so I cannot use getElementById it seems....

....so any old JavaScript voodoo will do....

....please?

Thanks.

-- Mark Kamoski
 
New Post
6/8/2018 1:40 PM
 

Here's one avenue from StackOverflow: https://stackoverflow.com/a/10111688

var $userFormItems = $('*[id^="dnn_ctr_Register_userForm_"]');

That will get  all the inputs on the form - from there you should be able to know the index of which one you're after.



Andrew Walker

Learn to make your own beer and wine at homeIf you enjoy making your own beer and/or wine - be sure to check out http://www.ForemostBrewing.com
 
New Post
7/13/2018 11:57 AM
 
...

Andrew Walker (and all) --

Thank you SO much for the help, and I got it working with your great advice.

I have 1 more question, as a follow-up.

Why do you use the $ in front of the array variable, $userFormItems, as I seem to have found that it is not necessary?

I seem to remember that the $ denotes some kind of relation to jQuery at large, and I think I understand the use as "A $ sign to define/access jQuery", so I think I get the use of $ on the selector. But I do not get the use of $ on the variable declaration and it seems to work without the $ too.

Please advise.


Anyway, FYI, I ended up using this...

...

var myUserFormItems = $('*[id^="dnn_ctr_Register_userForm_"]');

var myArrayLength = myUserFormItems.length;

for (var i = 0; i < myArrayLength; i++)
{

//This does work, and loops through all elements and shows the value, many of which are 'undefined' but the main elements, and index min is 0, and index max is 37.

myUserFormItems[" + i + "].value='" + myUserFormItems[i].value + "'");

}

//And, it turns out that, in DNN 8.03.3 here, for me, the indexes of note are...

var MyDefaultIndexForUserName = 5;
var MyDefaultIndexForPassword = 14;
var MyDefaultIndexForPasswordConfirmation = 21;
var MyDefaultIndexForDisplayName = 28;
var MyDefaultIndexForEmailAddress = 35;


Thanks.

-- Mark Kamoski

...
 
New Post
7/13/2018 1:55 PM
 

Excellent follow up question!!  

There's a difference between reading through code, and READING (actually loading the program into your mind as your reading). I do that because it let's me know, where ever I am in code - that the variable holds a jQuery object - so I already have the jQuery goodness w/ it.  I can't take credit, and assume this is a common practice that I read from someone much smarter a long time ago.

So, by your naming of myUserFormItems --- if I see that later in code - I don't know if it's an array of strings/ints/floats/objects, concatenated string, or some other object - I would have to go find where it's assigned and "load this script" into my memory - which has limited capacity as it is.

While you just wrote the code - you inherently know right now, but a couple weeks/months down the road, if you must revisit, you have to read and focus so much more to understand the code.   Where little cheats like pre-pending the jQuery object variables with $ - it eases the understanding and readability of the code.

In a very short/small function such as what you showed it's a moot point, but in larger functions/objects, it becomes much more valuable.  And consistency is key.



Andrew Walker

Learn to make your own beer and wine at homeIf you enjoy making your own beer and/or wine - be sure to check out http://www.ForemostBrewing.com
 
Previous
 
Next
HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...How can one use JavaScript to find a DNN element with dynamic ID on it?How can one use JavaScript to find a DNN element with dynamic ID on it?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out