Error : WPSC is undefined
While playing with custom master page file in WSS 3.0, suddenly my Picture Library’s was stopped working. Getting some javascript error like “WPSC is undefined”. I am getting this error only in the picture librarys.
Suddenly I found I have removed on line from the default.master page while copy / paste.
<SharePoint:ScriptLink language=”javascript” name=”core.js” Defer=”true” runat=”server”/>
Now it is works fine.
Dynamically changing class name in javascript
We can change the class of an element in javascript using
document.getElementById("element").class = "new Style";
We don’t need to use style.attribute name. We can also change the style using, style property
document.getElementById("element").style.color="red";
Horizontal Scroll Bar for listbox
Sometimes you may need to add Horizontal ScrollBar for a listbox. By default HTML does not support adding Horizontal ScrollBar to listbox.
The workaround is to create a DIV tag and insert the listbox in it. And set the overflow style to auto for the DIV tag.
<div style="width:80px; overflow-x:auto">
<select name="myselectbox">
<option value="1">This is option1</option>
<option value="2">This is option2</option>
<option value="3">This is option3</option>
<option value="4">This is option4</option>
<option value="5">This is option5</option>
</select>
</div>
This will display a Horizontal scrollbar if the item in listbox greater listbox width.
This can also work with ASP:Listbox control to, which is rendering as Listbox.
Programmatically submitting a FORM with Javascript
In asp.net, it allows to create only one <FORM> tag. If you put more than one <FORM> tag it will generate an error. But some times we require multiple form tags and submit buttons. Because <FORM> tag in asp.net always submit the form to the page itself.
Here is some code in javascript, it will submit the form using javascript.
function submitform()
{
document.forms[0].action = "mynewaspxpage.aspx";
document.forms[0].submit();
}
This function will set the action to mynewaspxpage.aspx and submit the form. Normally this option required for submitting forms automatically.
Clearing combobox items using javascript
I already posted some code to add and read values from dropdown lists using Javascript. Sometimes we require to reset the items to zero or need to clear the items in the dropdown list. Here is a simple code snippet which will reset the dropdown items.
function clearDropdown(dropdown)
{
var mycombo =document.getElementById(dropdown);
mycombo.options.length = 0;
return(false);
}
And you can use this function like this
<button onclick="javascript:clearDropdown('myoptions')">Reset Options</button>
Where myoptions is the dropdown to clear.