We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22815
    • 1,097 Posts
    Hi. I’m working on an extra for Polls Module - an Ajax Voting form.

    I decided to crib from AjaxSearch, and I was able to get the basics together. However, there’s one big stumbling block: I can’t fathom how to pass through a radio button value. Any field with an ID, I can pass through just fine. But I can’t have 3 radio buttons with the same ID.

    I want to have radio buttons so that the same form can degrade to normal submission.

    I’ve briefly looked at other options such as serialize, but I’m not clear what I’d do at the php end. Nor am I completely certain what The Ajax CMS prefers us to do.

    It’s now very late and I’ll probably have a brainwave in the morning, but I thought I’d ask the audience here what the preferred method is.
      No, I don't know what OpenGeek's saying half the time either.
      MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
      Forum: Where to post threads about add-ons | Forum Rules
      Like MODx? donate (and/or share your resources)
      Like me? See my Amazon wishlist
      MODx "Most Promising CMS" - so appropriate!
      • 18397
      • 3,250 Posts
      If I recall, you send the value of a radio selection as a single item in PHP by naming each radio button name[]. Then, you will have $_REQUEST[’name’] be the selection.
        • 22815
        • 1,097 Posts
        Ah, this was fun. My issue was getting something that I could pass via Ajax.Request to the url which would of course then work in the PHP. Looking at it again, I’d just forgotten that I was in JavaScript. I’d gotten hung up on using the scriptaculous library.

        For the record, I’ve ended up running through all the elements with a particular name and finding the value of the one that’s checked.
        	var sx=document.getElementsByName('poll_choice_id[]');
        	for(var j=0;j<sx.length;j++){
        		if(sx[j].checked==true){
        		s=sx[j].value;break
        		}
        	}
        	pars = 'onevote=' + onevote + '&pollid=' + pollid + '&poll_choice_id=' + encodeURIComponent(s);
        

        Although actually I probably don’t need the encode s.

        If anyone can improve this or point me to some fancy MODx-bundled js function that I’m unaware of, please do.
          No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
          MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
          Forum: Where to post threads about add-ons | Forum Rules
          Like MODx? donate (and/or share your resources)
          Like me? See my Amazon wishlist
          MODx "Most Promising CMS" - so appropriate!