www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to keep input text?

  1. #1
    Join Date
    Apr 2009
    Posts
    9

    how to keep input text?

    hi friends ,


    i am on make a dynamic input field creation code ,

    my problem is the entered text(value from "add proposition") is washing away , if i press new "add proposition"


    my 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+="<br />type propositon "+(k)+":<input type=\"text\" name=\"prop"+k+"\">is it answer?  <input type=\"checkbox\" name=\"ans"+k+"\">     ignore this one:<input type=\"checkbox\" name=\"ign"+k+"\">"            
           
        
    }


    </script> 

    my html code is
    PHP Code:
    <form  action="new.php" method="post">
       <
    fieldset>
    <
    legend>Add Question answer:</legend>
       
     
     
    question type:<br />
    True or False:<input type="radio" name="radio" value="t">
    Objective:<input type="radio" name="radio" value="o">
    Other:<input type="radio" name="radio" value="o">
    Quesion:<br />
    <
    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


     <
    input type="submit" name="submit">
     </
    fieldset>
    </
    form

    how i solve this problem ?

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    Still mostly the wrong way, but it works...

    Code:
    function add()
    {    
    	k = document.getElementById("num").innerHTML 
    	k = parseInt(k, 10); 
    	if(!k) {
    		document.getElementById("num").innerHTML = 1; k = 1;
    	} else { 
    		document.getElementById("num").innerHTML = k + 1; 
    		k++; 
    	}
    	var $item = document.createElement('div');
    	$item.innerHTML = 'type propositon ' + k + ': <input type="text" name="prop' + k + '"> is it answer?  <input type="checkbox" name="ans' + k + '">     ignore this one:<input type="checkbox" name="ign' + k + '">'
    	document.getElementById('cat').appendChild($item);
    }

  3. #3
    Join Date
    Apr 2009
    Posts
    9
    thraddash you are really great ...

    Thanks it works nicely.....


    any how.... what you mean by "wrong way"?

  4. #4
    Join Date
    Aug 2009
    Posts
    593
    Well, like the way I added the extra line of html with createElement, every other element and piece of text should be dynamically created in the same manner.

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