Friday, November 4, 2011

adjust the NewForm/EditForm fields width through the JavaScript in SharePoint

Modify the NewForm/EditForm fields width through the JavaScript as below:

script type="text/javascript" language="javascript"

//width
var inputs = document.getElementsByTagName("input"); //this is for textboxes
var textareas = document.getElementsByTagName("textarea"); //this is for multipline textbox
var selects = document.getElementsByTagName("select"); //this is for dropdown and date fileds

var width = 225;

for(var i=0;i{
if(inputs[i].className == "ms-long")
{

inputs[i].style.width = width + "px";
}

}

for(var i=0;i{
if(textareas[i].className == "ms-long")
{
textareas[i].style.width = width + "px";
}

}

for(var i=0;i{
if(selects[i].className == "ms-RadioText")

{
selects[i].style.width = width + "px";

}

}


/script

Reference URL: http://blogs.msdn.com/b/sharepointdesigner/archive/2008/01/25/modify-the-lengths-of-list-form-fields.aspx

Modify the lengths of list form fields through the javascript in Sharepoint

modify the NewForm/EditForm fileds width through the javascript as below:

<---script type="text/javascript" language="javascript">
//width
var inputs = document.getElementsByTagName("input"); //this for textboxes
var textareas = document.getElementsByTagName("textarea"); //this for multiline textboxes

var selects = document.getElementsByTagName("select"); //this for dropdown and date fileds
var width = 225;// need to set the wi

for(var i=0;i{
if(inputs[i].className == "ms-long" && (inputs[i].title=="custcity" || inputs[i].title=="cust_st" || inputs[i].title=="custzip") )
{
inputs[i].style.width = "75px";
}
else
{
inputs[i].style.width = width + "px";
}

}

for(var i=0;i{
if(textareas[i].className == "ms-long" && textareas[i].title=="stat_history")
{
textareas[i].style.width = width +200 + "px";
}
else
{
textareas[i].style.width = width + "px";
}

}

for(var i=0;i{
if(selects[i].className == "ms-RadioText")

{
selects[i].style.width = width + "px";

}

}
<--/script>