开发者

how to show only two text boxes at a time

how to show only two textbox only by next and previous button

this is my code,in this code when i click the next button show two textbox and aging when i click show the next two textbox..totally four开发者_如何转开发 textbox..i want only two text box per each click.......how can I achieve that ?

<script type="text/javascript">
var max=2;//highest number to go to
var currentIndex=0;
function Previous(){
  if(currentIndex>0){
    currentIndex--;
    postClick();
  }
}
function Next(){
  if(currentIndex<max){
    currentIndex++;
    document.getElementById("div").style.display="none" 
    postClick();
  }
}
function postClick(){//whatever you want to happen goes here    
  var sahan =new Array();
  sahan[currentIndex]==d;
  var d=document.getElementById("div");
  d.innerHTML+="<p><input type='text' name='name"+currentIndex+"[]'>";
  d.innerHTML+="<p><input type='text' name='topic"+currentIndex+"[]'>";        
  form1.text1.value=currentIndex;  
}
</script>

<form name="form1">
  <input type="button" value="Previous" onclick="Previous()"/>

  <input type="button" value="Next" onclick="Next()"/>

</form>
<div id="div"></div>
</body>
</html> 


In the postClick() function, try to remove the first "+" on line 4, i.e.:

d.innerHTML="...";

instead of

d.innerHTML+="...";


try like this

<script type="text/javascript">
        var max = 1; //highest number to go to
        var currentIndex = 0;
        function btnClick() {
            if (currentIndex == 0) {
                currentIndex++;
                postClick();
            }
        }

        function postClick() {//whatever you want to happen goes here

            var sahan = new Array();
            sahan[currentIndex] == d;            
            var d = document.getElementById("div");            
            d.innerHTML += "<p><input type='text' name='name" + currentIndex + "[]'>";
            d.innerHTML += "<p><input type='text' name='topic" + currentIndex + "[]'>";
            document.getElementById("div").style.display = "";  
        }
    </script>
</head>
<body>
    <form id="form1">
    <div>
        <input type="button" value="Previous" onclick="btnClick()" />
        <input type="button" value="Next" onclick="btnClick()" />
        <div id="div">
        </div>
    </div>
    </form>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜