Page 1/2 of commonly used JavaScript auxiliary code in ASP Programming

Source: Internet
Author: User

Some common AIDS Code

Click Back to the Code on the previous page:
<Form>
<P> <input type = "button" value = "back to previous step" onclick = "history. Back (-1)"> </P>
</Form>

Code of the pop-up warning box:
<Form>
<P> <input type = "button" value = "pop-up warning box" onclick = "alertbutton ()"> </P>
</Form>
<Script language = "JavaScript"> <! --
Function alertbutton () {window. Alert ("coming soon! ");}
// --> </SCRIPT>

Click to open a new window
<Form>
<P> <input type = "button" value = "open new window" onclick = "newwindow ()"> </P>
</Form>
<Script language = "JavaScript"> <! --
Function newwindow () {window. open ("http://www.mcmx.com", "", "Height = 240, width = 340, status = No, location = No, toolbar = No, directories = No, menubar = No ");}
// --> </SCRIPT> </body>

A confirmation box is displayed when you delete a record:
<Script language = "VBScript">
A = msgbox ("are you sure you want to delete this record? ", 1," NOTE ")
If a = 1 then
Location = "dodelete. asp? Id = <% = ID %> "// point to the dodelete. ASP page on which the deletion is executed.
Else
History. Go (-1)
End if
</SCRIPT>

Close the window
<A href = "/" onclick = "javascript: window. Close (); Return false;"> close the window </a>

Clear input and select
Onclick = "javascript: This. value ='' "onfocus =" This. Select () "onmouseover =" This. Focus ()"

Right-click shielding
<Body oncontextmenu = self. event. returnvalue = false>

Solution ie5.5
Style = "Left: 0px; width: 100%; Word-wrap: Break-word" you can change to the specified size, for example, 200px.

Image "reset" button
<Script language = "jscript">
Function myreset ()
{Document. login. Reset ();
Document. login. Focus ();}
</SCRIPT>

Draw a line table
<Table Style = "border-collapse: collapse">

Status Bar Information
<Form>
<P> <input type = "button" value = "status bar information" onclick = "statusbutton ()"> </P>
</Form>
<Script language = "JavaScript"> <! --
Function statusbutton () {window. Status = "coming soon! ";}
// --> </SCRIPT>

Minimize, maximize, and close the window
<Object ID = HH1 classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<Param name = "command" value = "minimize"> </Object>
<Object ID = HH2 classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<Param name = "command" value = "maximize"> </Object>
<Object ID = hh3 classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11">
<Param name = "command" value = "close"> </Object>

<Input type = button value = minimized onclick = hh1.click ()>
<Input type = button value = maximized onclick = hh2.click ()>
<Input type = button value = Disable onclick = hh3.click ()>
This example applies to IE

Hide link information in the status bar
<A href = "http: //"; onmouseover = "window. Status = 'none'; return true"> dream sky </a>

Text Box auto-scroll bar
<Textarea name = words rows = 18 Cols = 26 style = "border: 1 solid #000000; Background-color: White; font-size: 9pt; width: 188; overflow: auto "Wrap = hard> </textarea>

Select and copy all
<Form name = test> <input onclick = "javascript: highlightall ('test. select1 ') "type = button value = select and copy all> <br> <textarea name = select1 rows = 3 Cols = 46> Hello, welcome! </Textarea>
</Form>
<Script language = JavaScript>
<! --

VaR copytoclip = 1

Function highlightall (thefield ){
VaR tempval = eval ("document." + thefield)
Tempval. Focus ()
Tempval. Select ()
If (document. All & copytoclip = 1 ){
Therange = tempval. createTextRange ()
Therange.exe ccommand ("copy ")
Window. Status = "Contents highlighted and copied to clipboard! "
SetTimeout ("window. Status ='' ", 1800)
}
}
// -->
</SCRIPT>

Shield JavaScript errors
<Script language = "JavaScript">
<! --
Function killerrors (){
Return true;
}
Window. onerror = killerrors;
-->
</SCRIPT>

Refresh parent window when closing Child Window
<Script language = "JavaScript">
<! --
Self. opener. Location. Reload ();
Window. Close ()
-->
</SCRIPT>

Background Color Conversion
<Form>
<P> <input type = "button" value = "background color conversion" onclick = "bgbutton ()"> </P>
</Form>
<SCRIPT> function bgbutton (){
If (document. bgcolor = '# 00ffff ')
{Document. bgcolor = '# ffff ';}
Else {document. bgcolor = '# 00ffff ';}
}
</SCRIPT>

Check whether a string is composed of digits.
<Script language = "JavaScript"> <! --
Function checknum (STR) {return Str. Match (// D/) = NULL}
Alert (checknum ("1232142141 "))
Alert (checknum ("123214214a1 "))
// --> </SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.