2

I am trying to do the following. When pressing the button "submit" , i want the start price field in the form to echo the value returned from data-loader1.php.

i can echo it to the screen and to the console, but i cant get it to display in the form. How do i store the returned value in a variable that i can echo in the form's " start price " input field's value?

<?php
     if (isset($_GET['var_PHP_data'])) {
       echo $_GET['var_PHP_data'];
     } else {
     ?>
     <!DOCTYPE html>
     <html>
       <head>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
            <script src="http://malsup.github.com/jquery.form.js"></script> 
         <script>
             $(document).ready(function() {
                 $('#sub').click(function() {
                     var var_data = "Hello World";
                     $.ajax({
                         url: 'load-data1.php',
                         type: 'GET',
                          data: { var_PHP_data: var_data },
                          success: function(data) {
                              console.log(data);
                              var test = data;
                              console.log(test);
                              $("#input").value(data);
                             $('#result').html(data)
                          }
                      });
                  });
              });
         </script>
       </head>
       <body>
         <input type="submit" value="Submit" id="sub"/>
         
<form method = "post">
    
      
		</select>
		buy or sell :<select name="trade_sort">
  		<option value="Buy">Buy</option>
  		<option value="Sell">Sell</option>
  		
		</select>
		select currency pair :<select id="curr_pair" name="curr_pair">
  		<option value="EURUSD">EUR/USD</option>
  		<option value="GBPUSd">GBP/USD</option>
  		<option value="USDJPY">USD/JPY</option>
  		<option value="EURGBP">EUR/GBP</option>
  		<option value="USDCAD">USD/CAD</option>
  		<option value="AUDUSD">AUD/USD</option>
  		<option value="EURJPY">EUR/JPY</option>
  		<option value="GBPEUR">GBP/EUR</option>
  		<option value="USDCFH">USD/CFH</option>
  		<option value="EURCFH">EUR/CFH</option>
  		
		</select>
		Trade Date :<input type="text" name="date1" id="date1" alt="date" class="IP_calendar" title="Y/m/d">
		Amount :<input type="number" min="0" value="1000" step="1.0" name="amount">
        stoploss :<input type="number" min="0.00" value="0.00" step="0.01" name="stoploss">
        start price :<input id ="input" type="number"  min="0" value="<?php echo $test; ?>" step="0.00001" name="start_price">
 
    	<input type="hidden" name="closingDate" id="closingDate">
    	<input type="hidden" name="status" id="status">
        <input type="hidden"  min="0" value="1.0000" step="0.01" name="pip">
         <input type="hidden"  min="0" value="1.0000" step="0.01" name="pl1">
         <input type="hidden"  min="0" value="1.0000" step="0.01" name="pl2">
         <input type="hidden"  min="0" value="1.0000" step="0.01" name="multiplier" id="multiplier">
       
        <input type="submit" name="gg" value ="save trade">
    
    </form>


       </body>
     </html>
    <?php } ?>

2
  • Well, you use $.value() where you should be using $.val() inside your AJAX success Commented May 31, 2018 at 9:25
  • just to extend the @SamSwift웃 $("#input").value(data); replace this with $("#input").val(data); Commented May 31, 2018 at 9:27

1 Answer 1

4

To expand from my comment, inside your AJAX, you have the following;

success: function(data) {
    console.log(data);
    var test = data;
    console.log(test);
    $("#input").value(data);
    $('#result').html(data)
}

You are using $.value() in this, where the jQuery function is $.val() so the following should work;

success: function(data) {
    console.log(data);
    var test = data;
    console.log(test);
    $("#input").val(data);
    $('#result').html(data)
}
Sign up to request clarification or add additional context in comments.

Comments

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.