posts - 41, comments - 200, trackbacks - 0

My Links

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

Tag Cloud

Archives

Post Categories

Pre-populate a textbox using jQuery

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: ,,,
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Thursday, February 25, 2010 7:23 PM | Filed Under [ MOSS WSS Customization jQuery ]

Feedback

Gravatar

# re: Pre-populate a textbox using jQuery

Thanks. Very useful!
9/23/2010 10:50 PM | Dan
Gravatar

# re: Pre-populate a textbox using jQuery

Thanx good post! I used this :-)
2/15/2011 1:55 PM | Игромен
Gravatar

# re: Pre-populate a textbox using jQuery

thank you good job
11/14/2011 12:02 AM | davetiye
Gravatar

# re: Pre-populate a textbox using jQuery

very very useful
11/14/2011 12:03 AM | nikah şekeri
Gravatar

# re: Pre-populate a textbox using jQuery

Very very nice usefull.Thanks
12/13/2011 4:39 PM | Brautkleider
Gravatar

# re: Pre-populate a textbox using jQuery

Nice for this Comments
12/13/2011 4:43 PM | Gelinlik
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: