Kim Oliveros
Kim Oliveros

Reputation: 711

Text input from jquery not working

Hi I have a script that appends a set of constant string to a textarea it works fine if I click the button first but as soon as I input text on the textarea, the button does not append the constant string on the textarea if clicked again

here is my code for the click event:

    $("#apply").on("click",function() {
        var  orange = $("#agent_option").val(),
          lock = $("#agent_disallowed").val();

        $("#textareaFixed").html(orange + " " + lock );
    });

and Here is my html form:

<label for="agent_option" class="control-label">User-Agent :</label></div>
            <div class="col-md-6">
             <select id="agent_option" class="form-control input-sm">
                <option value="all">All</option>
                <option value="banana">Banana</option>
                <option value="apple">Apple</option>
                <option value="melon">Melon</option>
                <option value="lynx">Lynx</option>
                <option value="liger">Liger</option>
             </select>
            </div>
<div class="row">
                <div class="col-md-4">
                <label for="ax_disallowed" class="control-label">Disallow :</label></div>
                <div class="col-md-6">
                 <input class="form-control input-sm" id="ax_disallowed" type="text" value="<?=ax_default_disallow;?>">
                </div>
            </div>

   <div class="row">
   <div class="col-md-4">
    <button id="apply" class="btn btn-default">Register Player</button>
   </div>

This is my textarea:

<form  method="post" class="form-login">
              <div class="form-group">
                <textarea name="new_config" class="form-control" id="textareaFixed" cols="60" rows="16"><?=file_get_contents($open); ?></textarea>
              </div>

            </form>

please help me I tried google it but found irrelevant results. you guys are my only hope now :(

Upvotes: 0

Views: 58

Answers (3)

Ercan
Ercan

Reputation: 246

There isn't any input named as "agent_disallowed", you need to use correct id.

 $("#apply").on("click",function() {
     var  orange = $("#agent_option").val();
     var  lock = $("#ax_disallowed").val();
     $("#textareaFixed").html(orange + " " + lock );
 });

Upvotes: 1

Boshi
Boshi

Reputation: 230

You need to use append() instead of html()

Please try $("#textareaFixed").append(orange + " " + lock ); if you want to add the new text after the previous one.

If you use html(), it replaces the old stuff with the new one.

Upvotes: 1

bowheart
bowheart

Reputation: 4676

Change .html(...) to .val(...)

$("#apply").on("click",function() {
    var orange = $("#agent_option").val(),
        lock = $("#ax_disallowed").val();

    $("#textareaFixed").val(orange + " " + lock );
});

Upvotes: 1

Related Questions