accessing the input elements with array names in jquery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #1

    accessing the input elements with array names in jquery

    hi i have a problem i was using version 1.3 for jquery and i upgraded it to 1.8 and suddenly my code became buggy , i had 2 radio inputs with the name representative_ select[]
    [code=html]
    <input name="represent ative_select[]" type="radio" />
    [/code]

    and i need to check that if any one of these radio buttons is selected or not my previous working code was
    [code=javascript]
    if(jQuery("inpu t:radio[name=payment_op tion[]]:checked").leng th==0){
    str+='Please Select a Payment option\n';
    }
    [/code]
    and after upgrade i starting receiving syntax error i did some R&D and found that some functions are deprecated in the version 1.6+, so i changed it to the following but still no use as the square brackets need to be escaped so the \\ are used but still i am not doing it right here it is

    [code=javascript]
    if(jQuery(name= "representative _select\\[\\]").prop('checke d').length==0){
    str+='\Select a Representative option';
    }
    [/code]
    then i gave an id to the same input id='single_rep'
    and then run these two statements
    Code:
    alert(jQuery("#single_rep"));
    alert(jQuery(name="representative_select\\[\\]"))
    both of these statements alerted [object object]
    but when i append the prop() function with the 2 statements
    [code=javascript]
    jQuery(name="re presentative_se lect\\[\\]").prop('checke d')
    jQuery("#single _rep").prop('ch ecked')
    [/code]

    the first one says that prop is undefined and the second statement alerts true /false depending on the radio being checked or un-checked

    can somebody help me in this regard that what do i need to do
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    A silly question! Why do you put [] in the name for a radio button?

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      if you cant give a solution do not reply ANAS , do have some respect for other around the community, if you could have understood what i said then it would have been a lot better, a silly question is what you replied
      Why do you put [] in the name for a radio button?
      we can put [] with any type of input's name if we want to collect all of those input values into an array when posting on another page so please if you cant help dont be a DUMB ASS
      regards,
      Omer Aslam

      Comment

      • Anas Mosaad
        New Member
        • Jan 2013
        • 185

        #4
        Although I thought it was a silly question, you didn't get the point I wanted you to get. Having an array of values for any input type makes sense except for radio buttons -you have only one value selected. Do you agree with me on that?

        Regarding your point of respect, I think you need to learn how to respect others before you ask them to respect you. A community is not aimed for only answering your solutions. What you are asking for is a narcissistic community.
        When someone asks you a question respond to him with all the respect you want others to show you.

        Although I don't want to respond to you, I will through this feeling away now and tell you how to implement this if you still have a need:
        Code:
        if($("[name='representative_select[]']:checked").length==0){
            alert('Select a Representative option');
        }
        Please let me know if you need further clarifications.

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          Go away man i dont need your HELP , you still writing the code that wont work for 1.6+ jquery versions go check your code with version 1.8.2 , but thanks alot, and please dont respond on this thread , i am here from the last couple of years and never came across any such discussion , although i do come across alot of people who are new bees to development and dont have their concepts clear but have never responded like this , if you know some thing please dont be proud on it , cause once you didnt knew.
          take care.

          Comment

          Working...