/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] create <label> with for option

I am trying to create a form based on user input. if the user answers yes to a question then more form elements appear below here is my code

[CODE]function add_row(table,number,text,name,type){
var row = table.insertRow(number);

var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(text);
cellLeft.appendChild(textNode);

var cellRight = row.insertCell(1);
var el = document.createElement(‘input’);
el.type = type;
el.name = name;
cellRight.appendChild(el);
}
function show_created(){
var tbl = document.getElementById(‘step1’);
var lastRow = tbl.rows.length;
if(lastRow==4){
add_row(tbl,4,”MySQL Username”,”mysql_user”,”text”);
add_row(tbl,5,”MySQL Password”,”mysql_pass”,”password”);
//create question row
var row = tbl.insertRow(6);

var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(“Have you created a Database”);
cellLeft.appendChild(textNode);

var cellRight = row.insertCell(1);
var el = document.createElement(‘input’);
el.type = “radio”;
el.name = “created_db”;
el.value = “yes”;
el.id = “created_db_yes”
cellRight.appendChild(el);
var el = document.createElement(‘label’);
el.for = “created_db_yes”;
el.innerHTML = “Yes”
cellRight.appendChild(el);
var el = document.createElement(‘input’);
el.type = “radio”;
el.name = “created_db”;
el.value = “no”;
el.id = “created_db_no”
cellRight.appendChild(el);
var el = document.createElement(‘label’);
el.for = “created_db_no”;
el.innerHTML = “No”
cellRight.appendChild(el);
}
}[/CODE]

it works and it creates 3 new rows on my table but the label tags don’t work when i looked at my page with firebug i see it created the label tag but left out the for info so when u click on the text nothing happens. what do i need to do do make the label tag work.

Scott.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@felgallJul 16.2008 — for is a reserved word and so JavaScript uses htmlFor to reference the for attribute instead.

el.htmlFor = "created_db_yes";
Copy linkTweet thisAlerts:
@ratcatemeauthorJul 16.2008 — Thanks that fixed it i search google for half an hour and found nothing.

Scott.
×

Success!

Help @ratcateme spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...