开发者

Check with textbox

I have this question. I have a input type text and a button. Like this html:

<form id="browser-form">
    <div class="开发者_开发技巧filebrowser">
        <input type="text" id="browser-filepath">
    </div>
    <div class="upload submit"> 
        <a href="#" id="browser-submit" class="button">Uploaden</a> 
    </div>
</form>

But the question is. When the input type is empty. Je can not click on the button. When the input type is fil. Than you can click on the button. How can i fix that?

Thanks!


Assuming I've understood your question correctly, I think you want to prevent the link from doing anything unless the input has a value. If that's correct, then you can do this:

$("#browser-submit").click(function(e) {
    if(!$("#browser-filepath").val()) {
       e.preventDefault();
    } 
});

preventDefault is a method of the event object which, as the name suggests, prevents the default action of an event (in this case, following the link).

Here's a working example of the above.


function UpdateSubmitButton() {
var oTextBox = document.getElementById("browser-filepath");
var oButton = document.getElementById("browser-submit");

if(oTextBox.value == "") {
oButton.disabled = true;
}
else {
oButton.disabled = false;
}
}

Add an onchange="UpdateSubmitButton()" section to your text box, and you might want to add onload="UpdateSubmitButton()" to your document body.

This should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜