PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] How to append radio buttons in Javascript?

 November 15, 2022     javascript, jquery, json, laravel, laravel-6     No comments   

Issue

Trying to append radio buttons but displays [object Object]. What could be the problem in my code?

.append('<li>'+JSON.parse(data.responseText).question+' ('+JSON.parse(data.responseText).score+'pts) 
'+$.each(JSON.parse(data.responseText).choices, function(key, value){ {{Form::radio("radio", "value", ["class" => "form-control"])}}' })+' ');

Console

choices: Array(4)
0: {id: 121, quiz_question_id: 91, choice: "B", created_at: "2019-11-21 
05:35:42", updated_at: "2019-11-21 05:35:42"}
1: {id: 122, quiz_question_id: 91, choice: "G", created_at: "2019-11-21 
05:35:42", updated_at: "2019-11-21 05:35:42"}
2: {id: 123, quiz_question_id: 91, choice: "C", created_at: "2019-11-21 
05:35:42", updated_at: "2019-11-21 05:35:42"}
3: {id: 124, quiz_question_id: 91, choice: "C1", created_at: "2019-11-21 
05:35:42", updated_at: "2019-11-21 05:35:42"}
length: 4

Solution

$.each will not return the text. You will have to append the text within the callback. Please refer to the below sample:

     HTML: 
    <label for="search_field">Address</label>
    <input type='text' class='address_field' />
    <li class="some_class"></li>

    Javascript:

    $(document).ready(function() {

        var arr = [1,2,3];
        $.each(arr, function(key,val) {
            $('.some_class').append("(" + val + " )<li>sample1</li>");
        });
    });


Answered By - Arun Selin
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,213,563

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing