开发者

Creating a pulldown on website using values from php variable?

开发者 https://www.devze.com 2023-03-16 07:12 出处:网络
I am creating a form that the user can add more fields to their form if they need them for data. I am using a javascript function which is triggered by a action button that creates a row of textboxes

I am creating a form that the user can add more fields to their form if they need them for data.

I am using a javascript function which is triggered by a action button that creates a row of textboxes and one pull down field.

However in that row I need a pull down with the options "Yes and No", I already have them in a php array variable called $success

This is what I have to try and create a pull down but its not working.

ta[n]=document.createElement('option');
ta[n].value = <?php echo $success; ?>;
ta[n].name='success'+n;

Could someone help me out thanks for your time :)

This is the bulk of the current code

if(inp[c].value=='add') 
    {
       inp[c].onclick=function() 
        {
           ta[n]=document.createElement('input');
           ta[n].setAttribute('rows',1);
           ta[n].setAttribute('cols',20);
           ta[n].name='time'+n;
           document.getElementById('txtara').appendChild(ta[n])
           ta[n]=document.createElement('input');
           ta[n].setAttribute('rows',1);
           ta[n].setAttribute('cols',20);
           ta[n].name='event'+n;
           document.getElementById('txtara').appendChild(ta[n])
           ta[n]=document.createElement('input');
           ta[n].setAttribute('rows',1);
           ta[n].setAttribute('cols',20);
           ta[n]开发者_如何学C.name='supplies'+n;
           document.getElementById('txtara').appendChild(ta[n])
          var sel = document.createElement('select');


Here you go (i think this is what you wanted to do):

http://jsfiddle.net/maniator/4brz2/

var sel = document.createElement('select');

var ta = [];
var n = 0;

ta[n]=document.createElement('option');
ta[n].value = 'YES';
ta[n].name='success'+n;
ta[n].innerHTML = ta[n].value;
n++;
ta[n]=document.createElement('option');
ta[n].value = 'NO';
ta[n].name='success'+n;
ta[n].innerHTML = ta[n].value;
n++;

sel.appendChild(ta[0]);
sel.appendChild(ta[1]);


document.getElementById('here').appendChild(sel);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号