1

When something is typed in the url field and it is cleared again. Both input fields should be set to disable false.

The code is live here: http://jsfiddle.net/buyC9/117/

My HTML:

<h1>Upload image:</h1>
<input type="file" name="blog[opload]" id="blog_opload" class="imagec">
<input type="url" size="50" name="blog[url]" id="blog_url" class="imagec">
<div id="preview">
</div>

My JQUERY:

$('input').change(function() {
    $('.imagec').prop('disabled', true);
    $(this).prop('disabled', false);
    alert( $(this).text() );
    if ( $(this).attr('type') == 'url') {
        $('#preview').show().html('<img src=' + '"' + $(this).val() + '"' + ' />');
    }
});

 if( !$('.imagec').trim(this.value).length ) {
          alert('TOM');
 }

2 Answers 2

2

Try This :

$('input').change(function() {
    var el = $(this);
    if(this.value === ""){
        $('.imagec').prop('disabled', false);
        this.disabled = false;
        $('#preview').hide();
    }else{
        $('.imagec').prop('disabled', true);
        el.prop('disabled', false);
        alert( el.val() );
        if (el.attr('type') == 'url') {
            $('#preview').show().html('<img src=' + '"' + el.val() + '"' + ' />');
        }   
    }
});

EDIT :

See Feedle : http://jsfiddle.net

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

1 Comment

Try to type something in the url field. And then clear it. The upload field is still disabled
0
$('input.imagec').change(function() {
    $('.imagec').prop('disabled', true);
    var iAm = $(this);
    iAm.removeProp('disabled');
    if (iAm.val() == "") {
        $('.imagec').removeProp('disabled');
    }
    alert($(this).val());
    if ($(this).attr('type') == 'url') {
        $('#preview').show().html('<img src=' + '"' + $(this).val() + '"' + ' />');
    }
});

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.