0

I want to create a jscript to display number of columns depending on number of columns choosen. e.g if i choose 1, it should display column 1(text) and if i choose 2 it should display two text columns and so?

1 Answer 1

0

I have prepared a sample code based on my understanding of your requirement ,It may help you

 <!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#trid1").hide();
$("#trid2").hide();
var noofField=2;
$("#text").focusout(function(){

    if($.isNumeric( this.value ) )
    {

        for(i=1;i<=this.value;i++)
        {
            $("#trid"+i).show();
        }
        if(this.value<noofField)
        {
            var j=noofField-this.value;
            for(k=0;k<=j;k++)
            {
            var l=parseInt(this.value)+j;
            $("#trid"+l).hide();
            }
        }
    }


});

});
</script>
</head>
<body>

<p>If you click on the "Hide" button, I will disappear.</p>
<table>
<tr>
<td>
<input type="text" value="" id="text">
 </tr>

<tr id="trid1">


<td>
<input type="text" value="1">

</td>
</tr>


<tr id="trid2">

<td>
<input type="text" value="2">
</td>

</tr>

</body>
</html>

in the above code based on value entered in the first input field ( id=text) the other two field are shown

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.