Geeks With Blogs

News These postings are provided "AS IS" with no warranties, and confers no rights.
Locations of visitors to this page virtusa corp sharepoint virtusa.com shehan peruma
Shehan Peruma

Here’s the scenario:
I have a form which contains a textbox. This textbox should be populated with a query string value. Users should not be able to edit the value of the textbox while adding the item.

 

Solution:
The above can be achieved using a Content Editor Web Part (CEWP) and jQuery.

 

Steps:
1.    Append the NewForm.aspx url with the following: &PageView=Shared&ToolPaneView=2
2.     This will cause the ‘Add Web Part’ tool pane to show up.
3.    Add a CEWP to the page.
4.    Go the webparts properties and click the Source button
5.    Add the following:

// Note: replace this url with the url of the jquery library residing on the site!!
<script type="text/javascript" src="http://intranet/InternalDocuments/jquery-1.2.6.min.js"></script>

<script>
// This method retrieves the querystring value. If the querystring is missing it returns null. I’m not the author of the method; found it on the net, can’t remember from where though :)
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return 'null'
  else
    return qs[1];
}

//Note: The title attribute of my textbox is called ‘Source’. Replace it with the title attribute of the textbox on your form. The query string name is all called ‘Source’, replace as appropriate.
$(document).ready(function() {
    $("input[title$=Source]").val(unescape(getQuerystring('Source','')));
$("input[title$=Source]").attr('readonly','true');

});
</script>

6.    Hit the Save button
7.    Expand ‘Appearance’ and change ‘Chrome Type’ none. This step is optional.
 

Technorati Tags: ,,, Posted on Thursday, February 25, 2010 7:23 PM MOSS , WSS , Customization , jQuery | Back to top


Comments on this post: Pre-populate a textbox using jQuery

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
Thanks. Very useful!
Left by Dan on Sep 23, 2010 10:50 PM

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
Thanx good post! I used this :-)
Left by Игромен on Feb 15, 2011 1:55 PM

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
thank you good job
Left by davetiye on Nov 14, 2011 12:02 AM

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
very very useful
Left by nikah şekeri on Nov 14, 2011 12:03 AM

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
Very very nice usefull.Thanks
Left by Brautkleider on Dec 13, 2011 4:39 PM

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
Nice for this Comments
Left by Gelinlik on Dec 13, 2011 4:43 PM

# re: Pre-populate a textbox using jQuery
Requesting Gravatar...
Thanks for very useful script. jQuery an excellent framework
Left by Sans Ordonnance on Apr 18, 2012 7:40 PM

# davetiye, düğün davetiyesi
Requesting Gravatar...
I'll recommend it to everyone very helpful comments
Left by davetiye on Jun 29, 2012 3:33 AM

Your comment:
 (will show your gravatar)


Copyright © shehan | Powered by: GeeksWithBlogs.net