Souad
Souad

Reputation: 5084

Fix the size of a table even though "display none or block" in CSS

I have this HTML code:

<form:form method="get" action="${pageContext.request.contextPath}/get_info">
    <table id="tabmenu">
        <tr>
            <td><input type="radio" name="choice" id="np" onClick="Affichenp();"/>Nomet Prenom</td>
            <td><input type="radio" name="choice"id="ns" onClick="Afficheppr();"/>Numérode somme</td>
            <td><input type="radio" name="choice" id="cn" onClick="Affichecin();"/>CIN</td>
        </tr>
        <tr>
            <td><input type="text" name="nom" id="nom" class="round default-width-input" /></td>
            <td><input type="text" name="ppr" id="ppr" class="round default-width-input" /></td>
            <td><input type="text" name="cin" id="cin" class="round default-width-input" /></td>
            <td><input class="button round blue image-right ic-right-arrow" type="submit" value=""></td>
        </tr>
    </table>
</form:form>

This is the code of the functions called by javascript :

<script type="text/javascript">

function Affichenp() {
    document.getElementById("nom").style.display = "block";
    document.getElementById("ppr").style.display = "none";
    document.getElementById("cin").style.display = "none";
}

function Afficheppr() {
    document.getElementById("nom").style.display = "none";
    document.getElementById("ppr").style.display = "block";
    document.getElementById("cin").style.display = "none";
}

function Affichecin() {
    document.getElementById("nom").style.display = "none";
    document.getElementById("ppr").style.display = "none";
    document.getElementById("cin").style.display = "block";
}

When i click on a radio box, I want the input under it to display so when I click on the radio button the number of lines of the table changes. In other words, when I open my page on the first time, I have no input appear so I choose a radio button to give me an input to fill it... So the width of my td changes. Any solution?

Upvotes: 1

Views: 2789

Answers (2)

Patartics Mil&#225;n
Patartics Mil&#225;n

Reputation: 4938

Try to use style.visibility = "hidden" and style.visibility = "visible" instead!

Upvotes: 4

ASGM
ASGM

Reputation: 11381

You write that your problem is that the width of your <td> changes once an <input> is added. My suggestion would be to give your <td> a default width using CSS that's larger than the width of the <input> (200px is just an example, you can change it as appropriate):

#tabmenu td {width:200px;}

Also, you can simplify your functions into one by making the id an argument:

function Affiche(id) {
    document.getElementById("nom").style.display = "none";
    document.getElementById("ppr").style.display = "none";
    document.getElementById("cin").style.display = "none";
    document.getElementById(id).style.display = "block";
}

Upvotes: 2

Related Questions