JQuery + PHP get the Text and Value selected by Selectoption (with the selected city instance)

Source: Internet
Author: User
PHP code: [php] & lt; li & gt; & lt; spanclass = & quot; l2 & quot; & gt; City & lt;/span & gt; & lt; selectclass = & quot; city & quot; & gt; & lt; optionvalue = & quot; & gt; select the city & PHP code: [php]
  • CitySelect the city<% Foreach from = $ supportcity item = city key = k %>Selected <%/if % >>< % $ city. city_name %><%/Foreach %>
  • Region <% foreach from = $ supportcity item = city key = k %>Select Region<% Foreach from = $ city. areas item = area %><% $ Area. area %><%/Foreach %><%/Foreach %>
  • Jquery code: [javascript] $ ("select. city "). change (function () {var ccode = $ (this ). val (); $ ("select. area "). hide (); if (ccode) {$ ("select. area [citycode = "+ ccode +"] "). show () ;}}); var sltcity =$ ("select. city "). val (); if (sltcity) {$ ("select. area [citycode = "+ sltcity +"] "). show ();} is detailed below: jquery radio value, checkbox value, select value, radio selected, checkbox selected, select selected, and related settings to obtain the value of a set of radio selected items: var item =$ ('input [name = items] [checked] '). val (); get the text of the selected select item: var item =$ ("select [@ name = items] option [@ selected]"). text (); obtain the text of the selected select item: var item = $ ("select [name = items] option [selected]"). text (); or $ ("select [name = items]"). find ("option: selected "). text (); the second element in the select drop-down box is the selected value: $ ('# select_id') [0]. selectedIndex = 1; the select drop-down box value = 'Val' element is currently selected: $ ("select [name = items] option [value = 'Val']"). attr ("selected", "selected"); the second element of the radio Group is the selected item: $ ('input [@ name = items] '). get (1 ). checked = true; or $ ('input [name = items] '). attr ("checked", '1'); the value = 'Val' of radio is the currently selected item: $ ('input [name = items] [value = 'Val'] '). attr ("checked", "checked"); value: text box, text area: $ ("# txt "). attr ("value"); multiple choice box checkbox: $ ("input [name = 'checkbox': checked]"). each (function () {var val = $ (this ). val () ;}); single-choice radio: $ ("input [type = radio] [checked]"). val (); value of select in the drop-down box: $ ('select '). val (); select selected text value in the drop-down box: $ ("select "). find ("option: selected "). text (); control form element: text box, text area: $ ("# txt "). attr ("value", "); // clear content $ (" # txt "). attr ("value", '11'); // The multi-choice box for filling content checkbox: The second element of the checkbox is checked: $ ("input [name = items]"). get (1 ). checked = true; // Check $ ("input [name = items]"). get (1 ). checked = false; // check the value of the checkbox before the 'Val 'element: $ ("input [name = item] [value = 'Val']"). attr ("checked", true); or $ ("input [name = item] [value = 'Val']"). attr ("checked", "checked"); if ($ ("input [name = item] [value = 'Val']"). attr ('checked') = true) // determines whether the radio group radio has been checked: $ ("input [type = radio]"). attr ("checked", '2'); // select: $ ("# sel") for the project whose value is set to 2 "). attr ("value", '-sel3'); // set the value =-sel3 project as the currently selected item $ (" 1111 2222"). AppendTo ("# sel") // Add option $ ("# sel") in the drop-down box "). empty (); // clear the drop-down box jQuery to obtain the Value selected by Radio code $ ("input [name = 'Radio _ name'] [checked]"). val (); // select the Value of the selected Radio $ ("# text_id "). focus (function () {// code ...}); // event triggered when the object text_id gets the focus $ ("# text_id "). blur (function () {// code ...}); // event triggered when the object text_id loses focus $ ("# text_id "). select (); // Set the Vlaue value of the text box to the selected status $ ("input [name = 'Radio _ name'] [Value = 'value to select the value of radio '"). attr ("checked", true ); // Set Radio to the selected status based on the Value. jQuery gets the Value selected for the CheckBox $ ("input [name = 'checkbox _ name'] [checked]"); // select the set of checked CheckBox elements. if you want to get the Value, you need to traverse the set $ ("input [name = 'checkbox _ name'] [checked]").. each (function () {arrChk + = this. value + ',';}); // traverses the set of the selected CheckBox elements to obtain the Value $ ("# checkbox_id "). attr ("checked"); // get the status of a CheckBox (true/false if any) $ ("# checkbox_id "). attr ("checked", true); // Set the status of a CheckBox to selected (checked = true) $ ("# checkbox_id "). attr ("checked", false); // sets the status of a CheckBox to unselected (checked = false) $ ("input [name = 'checkbox _ name']"). attr ("checked", $ ("# checkbox_id "). attr ("checked"); // according to 3, 4, 5, you can analyze the meaning of the code $ ("# text_id "). val (). split (","); // separates the Value of Text with ',' and returns an array jquery1.3.2ISDARK: $ ("input [@ type = radio] [name = ISDARK] [checked]"). val () $ ("input [name = radioname] [value = radio value]"). attr ("checked", "checked ");

    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.