SoFunction
Updated on 2025-04-13

js usage method and function summary


43 Form composition
1: <form method="post" action="" name="thisForm">
2: <input type="text" name="myText">
3: <select name="mySelect">
4: <option value="1">First Choice</option>
5: <option value="2">Second Choice</option>
6: </select>
7: <br>
8: <input type="submit" value="Submit Me">
9: </form>
44 Access the text box content in the form
1: <form name="myForm">
2: <input type="text" name="myText">
3: </form>
4: <a href='#' onClick='();'>Check Text Field</a>
45 Dynamically copy text box content
1: <form name="myForm">
2: Enter some Text: <input type="text" name="myText"><br>
3: Copy Text: <input type="text" name="copyText">
4: </form>
5: <a href="#" onClick=" =
6: ;">Copy Text Field</a>
46 Detect changes in text boxes
1: <form name="myForm">
2: Enter some Text: <input type="text" name="myText" onChange="alert();">
3: </form>
47 Access the selected Select
1: <form name="myForm">
2: <select name="mySelect">
3: <option value="First Choice">1</option>
4: <option value="Second Choice">2</option>
5: <option value="Third Choice">3</option>
6: </select>
7: </form>
8: <a href='#' onClick='alert();'>Check Selection List</a>
48 Dynamically add Select item
1: <form name="myForm">
2: <select name="mySelect">
3: <option value="First Choice">1</option>
4: <option value="Second Choice">2</option>
5: </select>
6: </form>
7: <script language="JavaScript">
8: ++;
9: [ - 1].text = “3";
10: [ - 1].value = “Third Choice";
11: </script>
49 Verification Form Fields
1: <script language="JavaScript">
2: function checkField(field) {
3: if ( == “") {
4: (“You must enter a value in the field");
5: ();
6: }
7: }
8: </script>
9: <form name="myForm" action="">
10: Text Field: <input type="text" name="myField"onBlur="checkField(this)">
11: <br><input type="submit">
12: </form>
50 Verify Select item
1: function checkList(selection) {
2: if ( == 0) {
3: (“You must make a selection from the list.");
4: return false;
5: }
6: return true;
7: }
51 Dynamically changing the form action
1: <form name="myForm" action="">
2: Username: <input type="text" name="username"><br>
3: Password: <input type="password" name="password"><br>
4: <input type="button" value="Login" onClick="();">
5: <input type="button" value="Register" onClick=" = ‘'; ();">
6: <input type="button" value="Retrieve Password" onClick=" = ‘'; ();">
7: </form>
52 Using the Image Button
1: <form name="myForm" action="">
2: Username: <input type="text" name="username"><br>
3: Password: <input type="password"name="password"><br>
4: <input type="image" src="/""" value="Login">
5: </form>
6:
53 Encryption of form data
1: <SCRIPT LANGUAGE='JavaScript'>
2: <!--
3: function encrypt(item) {
4: var newItem = '';
5: for (i=0; i < ; i++) {
6: newItem += (i) + '.';
7: }
8: return newItem;
9: }
10: function encryptForm(myForm) {
11: for (i=0; i < ; i++) {
12: [i].value = encrypt([i].value);
13: }
14: }
15:
16: //-->
17: </SCRIPT>
18: <form name='myForm' onSubmit='encryptForm(this); ();'>
19: Enter Some Text: <input type=text name=myField><input type=submit>
20: </form>