0

I want to hide a specific input on a page unless a user types a Hotmail address into a different input. Whenever the user types in a hotmail address, I want to show the input. If the address is removed, I'd like it to disappear. How can this be accomplished with jQuery?

I know I'm going about this incorrectly, but here's what I have so far:

$(function() {

 if($("select#combobox").val() *= '@hotmail') {

   $('#hotm').show();

 }

 else {

   $('#hotm').hide();

 }

 });
1
  • 2
    *= is for multiplication, it has nothing to do with equality or pattern matching. Commented Feb 1, 2011 at 21:34

2 Answers 2

3

You can try something like this:

$("select#combobox").blur(function() {
  if ($(this).val().indexOf('@hotmail')>-1) 
    $('#hotm').show();
  else
    $('#hotm').hide();
});

this is to check after the user takes focus off the combobox...you might wanna use a different event depending on your needs/style, like .change() or whatever.

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

Comments

2

This checks direct on typing... Here is a working example: http://jsfiddle.net/Ltapp/

var myString = '@hotmail';
$("input").keyup(function () {
var value = $(this).val();
    if($(this).val().match(myString)) {
        $('#hotm').show();
    } else {
        $('#hotm').hide(); 
    }
});

1 Comment

@grearsdigital - beat me to it. nice +1

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.