简体   繁体   中英

JQuery change input field

I am working on the webpage which contains a input field that needs to be changed programmatically using stored string into the php variable.

This is my JQuery code and it is doing what i need.

$(function(){
$('.start').click(function(e) {
    var currentPage = "<?php echo $name;?>";
   $('input').val(currentPage);
   $('.textfield').prop("disabled", true );
   $('.textfield').css('cursor','not-allowed');
});
});

When I click start button name is inserted into the input element, but when i click submit button, error message popup that "Field is required". My question is, why changed input value doesn't work. If I add or remove letter then submit button is working and there is no field message popup.

Thanks

Disabled fields won't get submitted by forms. Hence, it says "Field is required". But there is another property which can be helpful in this kind of situation. Use readonly property. Replace the following line in your code instead of disabled property.

$('.textfield').prop("readonly", true );

Let us know if this solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM