duanjia7607 2012-09-04 11:15
浏览 33
已采纳

需要访问<form>中的<input>数据,该数据已附加了Javascript

I have an admin page where I add and delete table rows on the fly. The page comes loaded with the existent data in the database (mostly consisting in a sku_code and 5 different prices) but when I add rows on the fly, and fill them with the corresponding skus and prices, I want to save them as well in the database.

The problem is that what I do on the client-side with Javascript (add table rows on the fly) with innerHTML = '<input type="text"> is not accesible via $_POST variables of the main <form>

So basically i add via Javascript 's so i can fill them and save them as well in the database. But the $_POST values are empty. Javascript code works fine. I have no clue where should i start debugging.

here's some Javascript code i'm using

function insert_record(){

    var my_table = document.getElementById('my_table')
    var tr = my_table.insertRow(my_table.rows.length-1)
    //id-ul curent, numar toate row-urile - 1 (care este butonul OK)

    var c_id = my_table.rows.length-2

        tr.id = 'row_' + c_id + ''
    var tr_td_1 = tr.insertCell(0)
        tr_td_1.className = 'text2'
        tr_td_1.align = 'center'
        tr_td_1.innerHTML = 'SKU'
    var tr_td_2 = tr.insertCell(1)  
        tr_td_2.className = 'text3'
        tr_td_2.width = '63'
        tr_td_2.innerHTML = '<input name="sku_' + c_id + '" type="text" id="sku_' + c_id + '" size="33" value="">'

....this addes a inside the table just before the last which contains the submit button, after which there's the

  • 写回答

3条回答 默认 最新

  • doushi7761 2012-09-04 11:26
    关注

    You need to assign a label to element. Then you can grab it in next page.

    Instead of innerHTML = <input type="text"> try to use

    <script>
          function addElement(tag_type, target, parameters) {
            //Create element
            var newElement = document.createElement(tag_type);
    
            //Add parameters
            if (typeof parameters != 'undefined') {
              for (parameter_name in parameters) {
                newElement.setAttribute(parameter_name, parameters[parameter_name]);
              }
            }
    
            //Append element to target
            document.getElementById(target).appendChild(newElement);
          }
        </script>
    

    You can call this function below either click of even or manually addElement('INPUT','targetTag',{id:'my_input_tag', name:'my_input_tag', type:'text', size:'5'});

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化