0

This is my JS:

function showReturning(){
    document.getElementById("returningdate").style.display = 'block';

}

And this is my HTML:

        <input type="radio" name="triptype" value="roundtrip" onclick="showReturning()"/><label>Round Trip</label>

        <td class="hiddenReturning">
        <label>Returning:</label>
        <input type="text" name="returningdate" id="returningdate" required="required" placeholder="dd/mm/yy">
        </td>

And this is my CSS:

.hiddenReturning{
    display:none;
}

When I click the radio button, the text box is not being displayed.

1
  • If a tag's parent is hidden, even if the tag itself has display:block it will still be hidden. You need to unhide the parent tag as well. Commented May 2, 2014 at 11:36

5 Answers 5

1

The textbox is not hidden, it's the td that wraps it.
Either change the textbox only to be hidden or change the td's style.

This will hide the textbox:

   <td>
        <label>Returning:</label>
        <input class="hiddenReturning" type="text" name="returningdate" id="returningdate" required="required" placeholder="dd/mm/yy">
   </td>
Sign up to request clarification or add additional context in comments.

Comments

0

try This :

HTML

<input type="radio" name="triptype" value="roundtrip" onclick="showReturning()"/><label>Round Trip</label>

    <td class="hiddenReturning" id="new_id">
    <label>Returning:</label>
    <input type="text" name="returningdate" id="returningdate" required="required" placeholder="dd/mm/yy">
    </td>

JS

function showReturning()
{
document.getElementById("new_id").style.display = 'block';
}

CSS

#new_id{
display:none;
}

Comments

0

Change your css as follows :

<style type="text/css">
 #returningdate{
  display:none;
 }
</style>

Comments

0

i think it is working now. try this

<html>
    <head>
        <script type="text/javascript">

        </script>

        <style type="text/css">
            #returningdate
            {
                display: none;
            }
        </style>
    </head>

    <body>
        <input type="radio" id="radio" />Click<br />

        <td class="hiddenReturning">
            <label>Returning:</label>
            <input type="text" name="returningdate" id="returningdate" />
        </td>

        <script>
            var getback = document.getElementById('returningdate');
            function showReturning()
            {
                getback.style.display = 'block';
            }

            var radio = document.getElementById('radio');

            radio.addEventListener('change', showReturning, false);
        </script>
    </body>
</html>

fiddle here http://jsfiddle.net/h_awk/g92ps/

3 Comments

hi friends .. why are you add LINK tag ?
<link rel="stylesheet" type="text/css" href="style.css" /> why add style.css
sorry, you can ignore that, there is nothing in that file, the css is on the page itself, is the answer according to what you were looking for?
0
<input type="text" name="number" id="id" />

for show and hide

using javascript

document.getElementById("id").style.display="block";
document.getElementById("id").style.display="none";

using css

#id{
    display:block;
    display:none;
    }

using jQuery

$('#id').show();
$('#id').hide();

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.