Home php How to assign Input value via jQuery

How to assign Input value via jQuery

Author

Date

Category

There is a form with three INPUT (input, button and output) My goal Enter the value in the input field, when you click on the Send data to the handler and the resulting output in the last Input.

Form:

& lt; form action = "../ php / handlers / neural.php" Method = "POST" & gt;
      & lt; Input Type = "text" name = "input" id = "input" placeholder = "Enter the query" Autocomplete = "OFF" & gt;
      & lt; Input Type = "Button" id = "BTN" value = "Send" & gt;
      & lt; input name = "answer" id = "answer" autocomplete = "off" value = "" & gt; & lt; / form & gt;

Next follows script:

& lt; script & gt;
      $ ("# BTN"). Bind ("Click", Function () {
        Let Input = $ ("# Input"). Val ();
        Let Answer = $ ("# Answer"). Val ();
        $.ajax ({
            URL: '../PHP/Handlers/neural.php',
            Type: 'Post',
            Cache: False,
            Data: {INPUT, ANSWER},
            Datatype: 'HTML',
            BEFORESEND: FUNCTION (DATA) {
              $ ("# BTN"). Prop ("Disabled", True);
            },
            SUCCESS: FUNCTION (DATA) {
              $ ("# BTN"). Prop ("Disabled", False);
              Alert (DATA);
            }
          });
        });
      & lt; / script & gt;

At the end of the JQ scrippite there is alert, it correctly displays the processed data by the expected method (window in the browser)

Question how to assign this data to me

& lt; input name = "answer" id = "answer" autocomplete = "off" value = "" & gt;

I’m new to JQ and JS (CEP)

PS The script is located in front of the closing tag


Answer 1

You will help you setter val in jQuery .

Instead of

alert (data);

Put

$ ("# answer"). Val (Data);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions