Creating Dynamic Controls with Javascript

I was working on a search hack and needed the session state from ASP .Net controls and the ids from html controls using this hack: http://www.tqcblog.com/archive/2007/10/26/creating-a-custom-advanced-search-box-in-moss-2007.aspx.  So I came up with a creative solution.  I would add the html controls in the background.  Here is some code if you would like to add your own hidden html controls or just create some for fun:

var currentElement = document.createElement("input");

currentElement.setAttribute("type", "hidden");
currentElement.setAttribute("name", "YourName");
currentElement.setAttribute("id", "YourID");
currentElement.setAttribute("value", "YourValue");
document.getElementById("DivName").appendChild(currentElement);

You are going to want to create a div or a span to add your elements or you can do document.body.appendChild.  SharePoint for some reason did not like that statement, so I created a div before the button to add the elements.  You do not need to add a hidden element.  You can add a checkbox, but remember to add an element.display = "none"; or it will display the item.  If you have any comments or questions send them my way.  Hope you all have a good week!
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Wednesday, August 13, 2008 4:14 PM

Feedback

# re: Creating Dynamic Controls with Javascript

Left by Abhay Kr. Pandey at 5/15/2009 1:46 AM
Gravatar Quite Simple way of description. Was really worthful.

# re: Creating Dynamic Controls with Javascript

Left by priya at 6/10/2010 3:59 AM
Gravatar if division is not needed then how would the code been??

Your comment:





 
 

Copyright © MOSSLover

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski