javascript - How do I get text from input boxes to appear in a popup window? -



javascript - How do I get text from input boxes to appear in a popup window? -

how go extracting info input boxes , display in separate popup window @ click of button?

example below:

html coding:

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <table style="width: 50%" cellspacing="0" cellpadding="0"> <tr> <td>firstname</td> <td><input type="text" id="firstname"></td> </tr> <tr> <td>lastname</td> <td><input type="text" id="lastname"></td> </tr> <tr> <td>address</td> <td><input type="text" id="address"></td> </tr> <tr> <td>telephone</td> <td><input type="text" id="telephone"></td> </tr> </table> <input type="button" value="show details"> </body> </html>

i guess, simplest way send info 1 web page using method of html's forms.

let's say, input boxes implemented in file form.html:

<html> <body> <form action="./display.html" method="get"> <table> <tr><td>first name:</td><td><input type="text" name="firstname"></td></tr> <tr><td>last name:</td><td><input type="text" name="lastname"></td></tr> <tr><td>phone number:</td><td><input type="tel" name="phonenumber"></td></tr> </table> <input type="submit" value="submit"> </form> </body> </html>

if type in first , lastly name phonenumber , press submit button, redirected file display.html. furthermore, browser appends info of form url in next way:

display.html?firstname=albert&lastname=einstein&phonenumber=555-12345

(if albert einstein ;) )

more precisely, takes name info of each form element adds = , info given user. if more 1 form element within <form></form> tags, each of key-value pair separated &.

in order retrieve info in file display.html, have utilize bit of javascript:

<html> <body> <table> <tr> <td>first name: </td><td><span id="firstname"></span></td></tr> <td>last name: </td><td><span id="lastname"></span></td></tr> <td>phone number: </td><td><span id="phonenumber"></span></td> </tr> </table> <script> var queryvars={}; function getqueryvariables() { var query = window.location.search.substring(1); var vars = query.split("&"); (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); queryvars[pair[0]]=pair[1]; } } getqueryvariables(); document.getelementbyid("firstname").innerhtml=queryvars['firstname']; document.getelementbyid("lastname").innerhtml=queryvars['lastname']; document.getelementbyid("phonenumber").innerhtml=queryvars['phonenumber']; </script> </body> </html>

it takes after ? of current url, namely, firstname=albert&lastname=einstein&phonenumber=555-12345, splits @ every &, such end list of key-value pairs. after that, splits each of these key-value pairs @ = , stores info in queryvars variable. finally, info inserted corresponding <span></span> of table displayed user.

i hope, answers question.

javascript html5 popup

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -