简体   繁体   中英

Populate form data based on previous field

I have a form that i want to auto populate the last 2 fields based on field 2 data. Here is my form.

<form method="post">
<table>  <tr><b>Add new data using form below</b></tr>       
 <tr><td>  Keyword:  </td><td> <input type="text" name="keyword" id="keyword"><br></td></tr>
<tr><td> Block?: </td><td><input type="text" name="block" id="block"><br></td></tr>
<tr><td> Phone #:</td><td> <input type="text" name="phone" id="phone"><br></td></tr>
<tr><td> Reason: </td><td> <input type="text" name="reason" id="reason"><br></td></tr>
  <tr><td> </td><td align="left"> <input type="submit" name="submit" value="Submit  Data"></td></tr>
    </table>
      </form>

So the phone and reason will auto populate based on the block number entered. No necessarily looking for someone to do it.. maybe just guide me in a direction to get answer.

Sounds like a job for jQuery. Try a blur function for #block field:

$('#block').blur(function() {
 // get value, based on this, populate value of your other fields
});

http://api.jquery.com/blur/

This is how you can show things based on a form element input without refreshing the page.

JQuery Ajax与JQuery文本框模糊事件一起使用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM