user2871282
user2871282

Reputation: 9

how to send data from form in page to option tag in other page

I did a form by jotform site contains two pages or two forms I want to send data of username from newuser.php page to add to option tag in previllige.php page I write the js code right but when I enter the data and click add button the result still "please wait " only without send data to other page

there is the code of two pages first page: newuser.php and its code is:

$(function () {
            $("#btnQueryString").bind("click", function () {
                var url = "previliges.php?name="  + encodeURIComponent($("#addItem").val()) ;
             //   window.location.href = url;
                document.location.href = url;

          });
        });
<div id="cid_6" class="form-input">
          <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="addItem" name="username" size="20" value="" />
        </div>

second page: previllige.php and code of it :

<script language="javascript">
    window.onload = function () {
    var url = document.location.href,
        params = url.split('?')[1].split('&'),
        data = {}, tmp;


        //alert(params);
        var a = url.substr(url.lastIndexOf('=') + 1);
        //alert(a);


          var opt = document.createElement("option");
        document.getElementById("lbldata").options.add(opt);
         opt.text = a;
         $("#lblData").append('<option>'+opt.text+'</option>');

        }
</script>

 <select class="form-dropdown validate[required]" style="width:150px" id="lbldata" name="username">
            <option value="">  </option>
            <option value="amal"> amal </option>

          </select>

Upvotes: 0

Views: 181

Answers (1)

Labib Ismaiel
Labib Ismaiel

Reputation: 1340

I didn't get why you are doing this:

var a = url.substr(url.lastIndexOf('=') + 1);

but I am assuming you want to extract the params from url, but what you are doing is extracting the whole url untill the letter next to the last equal sign, I don't know why you did this, but this might be the result why you're not getting the name correctly in the second page. your params array in your code contains the real parameters, you should use it to set the value of var a

Upvotes: 1

Related Questions