Thursday, 15 July 2010

Return a value to a text input field from php with javascript -



Return a value to a text input field from php with javascript -

i've got dropdown field in php table list of workcodes. after workcode selected need lookup rate table depending on workcode , input input field. in workcode dropdown i've got onchange event execute javascript.

in javascript execute rate.php how value in rate.php field?

the workcode dropdown:

//workcode drop downwards $get5 = mysqli_query($con,"select * va_workcodes order briefdesc"); $option_wc = "<select name='wc' id='wc' onchange='getrate()'>"; while($row5 = mysqli_fetch_array($get5)) { $option_wc .= "<option value = '"; $option_wc .= $row5['wcno']; $option_wc .= "'>"; $option_wc .= $row5['briefdesc']; $option_wc .= "</option>"; } echo $option_wc; echo "</select>";

the rate field

echo "<input name='rate' id='rate' type='text' />";

the javascript/jquery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> function getrate(){ $.get("rate.php"); } </script>

rate.php

<?php $getrate1 = mysqli_query($con,"select * rates ....."); while($row1 = mysqli_fetch_array($getrate1)) { $stdrate = $row1['stdrate']; } ?>

so need homecoming $stdrate rate.php inputfield (rate)

make next changes code:

rate.php

<?php $getrate1 = mysqli_query($con,"select * rates ....."); while($row1 = mysqli_fetch_array($getrate1)) { $stdrate = $row1['stdrate']; } echo $stdrate; // print rate in end ?>

javascript/jquery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> function getrate(){ $.get("rate.php", function(data) { // add together callback success , retrieve printed value parameter $("#rate").val(data); }); } </script>

the problem making ajax call, not returning it's result, have done printing, after returning have consume result have done in js creating callback function.

javascript php jquery input

No comments:

Post a Comment