0

I have a text input with an id of auto_change_date and i am trying to hide it on page load using:

$(document).ready(function(){
    $("#auto_change_date").hide();
});

but its just not hiding it

i am then using this code to make it display (.show) when a select option is selected:

<script type="text/javascript">
$('#status').on('change',function(){
    if( $(this).val()==="Auto Change"){
    $("#auto_change_date").show()
    }
    else{
    $("#auto_change_date").hide()
    }
});
</script>
13
  • What error do you get in the browser console? Commented Jan 4, 2014 at 11:01
  • no error, the text input just still displays Commented Jan 4, 2014 at 11:01
  • can you make a fiddle.net ??? Commented Jan 4, 2014 at 11:02
  • Ok, can you show the HMTL you're applying it to? Commented Jan 4, 2014 at 11:02
  • have you include the jquery library? Commented Jan 4, 2014 at 11:03

7 Answers 7

1
<input type="text" name="auto_change_date" onclick="ds_sh(this);" />

you are missing here id

put it as follows

<input type="text" name="auto_change_date"  id="auto_change_date" onclick="ds_sh(this);" />

now your jquery will work fine

See Fiddle

Sign up to request clarification or add additional context in comments.

Comments

1

Nothing is wrong with Your jQuery. But I would suggest you to use Pure CSS

<style>
    #auto_change_date {
        display:none;
    }
</style>

OR, Simple JavaScript

  document.getElementById('auto_change_date').style.display = 'none';

1 Comment

yep. i agree with satpal. i don´t think for what you want its necessary to use javascript... pure css is the best way
1

Add html input type = "text" with id = "auto_change_date"

<input type="text" id="auto_change_date" />

Now add following javascript function:

$(document).ready(function(){
    $("#auto_change_date").hide();
});

Its Working fine for me.

Comments

0

With vanilla Javascript

var input = document.getElementById('auto_change_date');
input.style.display = 'none';

or

input.style.visibility = 'hidden';

Comments

0
 <style>
    .hidden{
        display:none;
    }
</style>


<script type="text/javascript">
$(document).ready(function(){
$('#auto_change_date').addClass('hidden');
$("#auto_change_date").hide();
});
</script>

the div should be made display:none at first inorder to apply this

Comments

0

You are not defining id to element and you should add jquery js to work this.

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

Html :

<input type="text" id="auto_change_date" name="auto_change_date" onclick="ds_sh(this);" />

1 Comment

If you want this using element.hide() Check fiddle (jsfiddle.net/xTHt5/4)
0

simply try something like this

    <input type="text"  id="auto_change_date" name="auto_change_date" onclick="ds_sh(this);" />

your javascript code should be like this

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
    $(document).ready(function(){
        $('#status').on('change',function(){
            if(this).value ==="Auto Change" ){
                $("#auto_change_date").show();
            } else {
                $("#auto_change_date").hide();
            }
        });
    });
</script>

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.