0
function td(id,inc)
{
    var idnew=$(id).attr("id");
    var tr=id;
    var tdchild = document.createElement('td');
    tdchild.innerHTML="<input type=radio name=rd"+idnew+" value=rd"+idnew+"><input type=text name="+idnew+"[] size=5>";
    tdchild.setAttribute("id",inc);
    tr.appendChild(tdchild);

} 

My code generates dynamic radio buttons as above. But i am having problems in posting radio buttons

2 Answers 2

1

Radio and checkbox inputs will only be posted if they are set/checked. Otherwise they won't show up in the post.

I always recommend doing things incrementally. Try first doing this with static html. Get that working. Then come back and make it dynamically generated.

Sign up to request clarification or add additional context in comments.

Comments

0

This bit:

> function td(id,inc) {
>     var idnew=$(id).attr("id");

makes no sense to me. What is the value of id passed to the function? If it's an element, then its id property can be read directly:

  var idnew = id.id;

if it's a string id, then it can be used as–is (if you select an element by id, then you must already know it):

  var idnew = id;

In this part:

  tdchild.innerHTML="<input type=radio name=rd"+idnew+" value=rd"+idnew+"><input type=text name="+idnew+"[] size=5>";

Consider creating base elements then cloning them and changing their names and values before adding them to the form. Finally, when using HTML, always enclose attribute values in quotes. There are rules for what must be in quotes and what doesn't need to be, but rather than remember the rules, just always use quotes (I perfer to use single for script and double for HTML), so:

  tdchild.innerHTML = '<input type="radio" name="rd' + idnew + '" value="rd' + idnew +
                      '"><input type="text" name="' + idnew + '[]" size="5">';

HTML allows CDATA attributes to be unquoted provided the attribute value contains only letters (a to z and A to Z), digits (0 to 9), hyphens (ASCII decimal 45) or, periods (ASCII decimal 46). Attribute values can be quoted using double or single quote marks (ASCII decimal 34 and 39 respectively). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa.

From HTML 3.2, later versions of HTML keep compatability. As can be seen, if the square bracket characters "[' and "]" are to be part of a name attribute, the whole attribute value must be in quotes.

2 Comments

I know these rules but my problem is not yet solved. I need to retain all the radio buttons formed after the post is carried out.
If you know the rules then put the name of the inputs in quotes. What do you mean by "retain all the radio buttons formed after the post is carried out"? Do you mean they should be posted, or stay in the page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.