javascript - Php: How to get textbox value from mysql database without submitting the form -
i want check values either 1 of 2 textboxes text boxes matches value other without submitting form. keypress event handling this, sending value jour_info.php page get_sid.php page. have 2 files
- jour_info.php
- get_sid.php
the code in first file
<form method="post" name="journ_form" > p-issn/isbn<br/><input name="printissn" id="printissn_input" type="text" value=""> <input type="text" name="pissnsid" id="pissnsid" style="width: 30px;" autocomplete="off" value=""> <span style="color: red;" id="feedback"></span> </form> <script type="text/javascript"> $(document).ready(function(){ $('#feedback').load('get_sid.php').show(); $('#printissn_input').keyup(function(){ $.post('get_sid.php', {printissn: journ_form.printissn.value}, function(result) { //$('#feedback').html(result).show(); document.getelementbyid('pissnsid').value = result; }); }); $('#pissnsid').keyup(function(){ $.post('get_sid.php', {pissnsid: journ_form.pissnsid.value}, function(result) { document.getelementbyid('printissn_input').value = result; }); }); });
the code in second file
<?php include 'auth.php'; $printissn = $_post['printissn']; $pissnsid = $_post['pissnsid']; if($printissn){ $check = mysql_query("select printissn, pissnsid jour_entries printissn='$printissn'"); $check_num_rows = mysql_num_rows($check); while($row = mysql_fetch_array($check)){ //$get_printissn = $row['printissn']; $get_printissnsid = $row['pissnsid']; if($check_num_rows == 0){ echo ''; } else if($check_num_rows == 1){ echo $get_printissnsid; } } } else if($pissnsid){ $check = mysql_query("select printissn, pissnsid jour_entries pissnsid='$pissnsid'"); $check_num_rows = mysql_num_rows($check); while($row = mysql_fetch_array($check)){ $get_printissn = $row['printissn']; //$get_printissnsid = $row['pissnsid']; if($check_num_rows == 0){ echo ''; } else if($check_num_rows == 1){ echo $get_printissn; } } } ?>
now working fine, problem when value entered in first text box showing corresponding match in second text box. in case if value doesn't match 2 fields , user needs enter manually data, problem arises. when there no match , user enters value in first textbox, second textbox value disappears. how solve that?
try this:
jour_info.php changes:
$('#pissnsid').keyup(function(){ $.post('get_sid.php', {pissnsid: journ_form.pissnsid.value}, function(result) { if('' != result) document.getelementbyid('printissn_input').value = result; }); });
Comments
Post a Comment