1

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

5
  • can you past your full code along with html Commented Jul 8, 2015 at 13:04
  • share the method which is giving the alert Commented Jul 8, 2015 at 13:04
  • 1
    can you try $('input').val(currentPage).change(); Commented Jul 8, 2015 at 13:04
  • Ya, changing value programatically doesn't fire any event. Now it's hard to figure if it is your issue with so little info and relevant code in question itself. How FORM is validated? Commented Jul 8, 2015 at 13:10
  • $('input').val(currentPage).change(); - does not work, already tried that. It is Ispring Quiz Maker app and html is generated through the JS and Json. Commented Jul 8, 2015 at 13:24

1 Answer 1

1

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.

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

2 Comments

Changed, but nothing, This is Quiz made with Ispring Quiz Maker and I think that problem is in the main player.js. I don't get it how submit works if i write something, but if value is changed using JQuery it doesn't.
You sure that your validation works fine? We can submit forms when values are added using JQuery. I can't guess what exactly the problem is. Share the part of your html and js (validation part) that you suspect.

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.