Suppose we have the following page:
<Input type = "text" name = "textname" id = "text_id" value = "">
No more...
The following describes how to obtain various values in FORM;
Function get_form_value (){
/* Obtain the value of TEXT. AREATEXT */
Var textval = $ ("# text_id"). attr ("value"); // or
Var textval = $ ("# text_id"). val ();
/* Obtain the value of the single-choice button */
Var valradio = $ ("input [@ type = radio] [@ checked]"). val ();
/* Obtain the value of the check box */
Var checkboxval = $ ("# checkbox_id"). attr ("value ");
/* Get all values in the drop-down list */
Var selectval = $ ('# select_id'). val ();
// Obtain the value selected from the drop-down list. This method works for all drop-down lists.
// This method works for all the drop-down boxes
// If you obtain an ID, $ ('# id> option'). each ().
$ ('Select> option'). each (function (){
If ($ (this). attr ('selected') = true)
{
Alert ($ (this). text ());
}
})
}
3. Other processing of the form:
// Control form elements:
// Text box, text area:
$ ("# Text_id"). attr ("value", ''); // clear the content
$ ("# Text_id"). attr ("value", 'test'); // fill in the content
// Multiple choice box checkbox:
$ ("# Chk_id"). attr ("checked", ''); // value not selected
$ ("# Chk_id"). attr ("checked", true); // The selected value
If ($ ("# chk_id"). attr ('checked') = undefined) // you can check whether the selected
// Single-choice group radio:
$ ("Input [@ type = radio]"). attr ("checked", '10'); // set the single-choice button with value = 10 to the selected item
// Select from the drop-down list:
$ ("# Select_id"). attr ("value", 'test'); // set the project with value = test as the selected item
$ ("<Option value = 'test'> test </option> <option value = 'test2'> test2 </option> "). appendTo ("# select_id") // Add the option in the drop-down box
$ ("# Select_id"). empty (); // clear the drop-down list