Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a series of Form Elements each with different names, I'll post one as an example. I cannot hard code the name into Jquery because unless I inspect the element, I won't know the name.

With that aside heres the element:

<label class="checkbox">
    <input type="checkbox" 
        name="aisis_options[package_Aisis-Related-Posts-Package-master]"
        value="package_Aisis-Related-Posts-Package-master" checked="" /> 
    Aisis-Related-Posts-Package-master 
    <a href="#">(Disable)</a>
</label>

The catch is to do this:

Grab the name of this element - upon clicking disable - and do two things, one - if the element is checked, which in this case it's not, unchecked it, two pass the name to a php variable, which then can do processing.

How would I do this? Jquery is not my strong area.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
222 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is a example without knowing more of your code:

$(function () {
    $('input:checkbox').click(function () {
        $(this).prop('disabled', true);
        var iName = this.name;
        $.ajax({
            url: "file.php",
            data: {
                'inputname': iName
            },
            success: function (data) {
                alert(data.returned_val);
            }
        })
    })
})

Demo here

If you want to reach the input via name directly you need to use double backslasshes to escape the square brackets and reach that input via name. Use:

$('input[name=aisis_options\[package_Aisis-Related-Posts-Package-master\]]')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...