www.webdeveloper.com
Results 1 to 4 of 4

Thread: javascript input field not working..?

  1. #1
    Join Date
    Apr 2009
    Posts
    9

    javascript input field not working..?

    hey friend i am trying to use automatic html input creation using java script for my new project ....


    my problem is the field "type propositon 1:is it answer? ignore this one:" not come into input variable such as $_POST['prop1']


    i used
    PHP Code:
    pint_r($_POST
    and the result was
    Code:
    Array ( [radio1] => on [cid] => 65 [desc] => dfdfdfdfd [submit] => Submit )


    why my javascript created input field come into role?


    my php html code is

    PHP Code:
    <table>
      <
    form  action="new.php" method="post">
       
       
     <
    tr><td>
     
    question type:<br />
    True or False:<input type="radio" name="radio1">
    Objective:<input type="radio" name="radio2">
    Other:<input type="radio" name="radio3" >
    </
    td></tr>
    <
    textarea name="desc" rows="6" cols="35" ></textarea> <br />
    <
    a href="javascript:add()" ><b>add proposition</b></a
    <
    div id="cat"></div>
    <
    div id="num" style="display:none;"></div>
    <
    br> </table
    and the java script is ...

    PHP Code:
      <script language="javascript" type="text/javascript">
       
        function 
    add()
        {   
            
    k=document.getElementById("num").innerHTML
            k
    =parseInt(k);
             if(!
    k)
            {
    document.getElementById("num").innerHTML=1;
            
    k=1;} 
            else{
               
    document.getElementById("num").innerHTML=k+1;
               
    k++;
            }  
             
    document.getElementById("cat").innerHTML+="<tr><td>type propositon "+(k)+":<input type=\"text\" name=\"prop"+k+"\"><td>is it answer? </td> <td> <input type=\"checkbox\" name=\"ans"+k+"\"></td><td><td>     ignore this one:</td><input type=\"checkbox\" name=\"ign"+k+"\"></td></td></tr><br>"            
           
        
    }


    </script> 
    Last edited by remshad; 01-28-2011 at 05:23 AM.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You can not nest a table's row inside a div element. It is HTML illegal.

    You should use TBODY elements instead of DIVs if you want to add new rows into a TABLE. And you should use DOM methods (createElement(), createTextNode(), appendChild()...) not innerHTML. innerHTML is not a standard DOM method and, in case of IE, it works as a read-only method in case of tables and their elements (tr, td...)

    DOM example:
    http://www.howtocreate.co.uk/tutoria...ript/domtables

  3. #3
    Join Date
    Apr 2009
    Posts
    9
    i am not lazy ... but new in the field of DOM element ...

    http://www.w3schools.com/jsref/met_table_insertrow.asp used InnerHTML ?

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I would rather use document.createElement(). Need an example?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles