/    Sign up×
Community /Pin to ProfileBookmark

Trying to add Html code dynamically to a web form

Hi!

I am trying to add Html code dynamically to my web form with a js function, but I can’t. I want to add a new row with columns and form objects, and I am trying to do it thus:

The js function:

[code]
function check_Prod() {

var prod = document.form_newProd.product.value

switch(prod) {

case “22”:
[B]var otherProd = document.getElementById(‘others’);[/B]
otherProd.innerHTML = “<tr><td height=’30’ colspan=’2′ align=’center’></td><td colspan=’4′><span id=’otherP’ class=’letter4′><span id=’ast’ class=’RedAst’>*</span>&nbsp;Specify the Product:</span>&nbsp; <input type=’text’ name=’writeProd’ class=’letter1′></td></tr>”;
break;

case “27”:
[B]var otherProd = document.getElementById(‘others’);[/B]
otherProd.innerHTML = “<tr><td height=’30’ colspan=’2′ align=’center’></td><td colspan=’4′><span id=’otherP’ class=’letter4′><span id=’ast’ class=’RedAst’>*</span>&nbsp;Specify the Product:</span>&nbsp; <input type=’text’ name=’writeProd’ class=’letter1′></td></tr>”;
break;

default:
[B]var otherProd = document.getElementById(‘others’);[/B]
otherProd.innerHTML = “”;

}

}
[/code]

The ‘product’ select object:

[code]
<select name=”product” onChange=”return check_Prod()”></select>
[/code]

And inside the table:

[code]

<td><input type=”text” name=”type”></td>
</tr>

[B]<span id=”others”></span>[/B]

<tr>
<td height=”30″ align=”left” valign=”middle” class=”letter4″><span class=”redAst”>*</span>&nbsp;Offer Title:&nbsp;</td>


[/code]

None error appears, but the Html code is not added, simply nothing happens..
What is wrong?

Thank you

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @erick30 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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