emperor 0 Report post Posted May 22, 2005 I'd like to know if there's a way to "autofill" form fields. On a web page (that I call A), i have a form with two text fields called F1 and F2. I want that clicking on a link on another page (B, for example) the page A will open and the field F1 will contain, for example, "choice 1". While clicking on another link in the same page ( the field F1 will contain "choice 2".I hope that you have understand my explanation. Share this post Link to post Share on other sites
Tyssen 0 Report post Posted May 22, 2005 You can use $_SERVER['HTTP_REFERER'] to detect what page the user is on before arriving at the form then use an if else statement to print out a different value for each case e.g. <input type="text" value="<? php if ($something = $_SERVER['HTTP_REFERER']) {print "first message";else print "second message";}?>"> Share this post Link to post Share on other sites
theRealSheep 0 Report post Posted May 25, 2005 I'm sure ther would be a better way of doing this, but I have an answer for you using JavaScript. Your suggested 'Page B' would contain the following <script> tag, where "a.html" is the path to your suggested 'Page A'. <script language="JavaScript1.2" type="text/javascript"><!--function NextPage(choice) { document.FormB.inputValue.value = choice; openWin = window.open("a.html", "Page_A", ""); }//--></script>then, your 'links' on Page B would be buttons in a form, where the text you want entered on the next page is in the onClick event. eg. Input for Choice 1. <form name="FormB"> <input type="hidden" name="inputValue" value=""> <p><input type="button" name="choice_1" value="This is 'Choice 1'" onClick="NextPage('Input for Choice 1')"> <p><input type="button" name="choice_2" value="This is 'Choice 2'" onClick="NextPage('Input for Choice 2')"> </form> Now over on 'Page A', place the following script, where F1 is the name of the input field (which is in the form named FormA, as shown below). <script language="JavaScript1.2" type="text/javascript"><!--function fillField() { document.FormA.F1.value = window.opener.document.FormB.inputValue.value;}//--></script>... and then you will need to add an OnLoad event to the <body> tag of Page A to transfer the value <body onLoad="fillField()"> <form name="FormA"> <p><input type="text" name="F1"> <p><input type="text" name="F2"> </form> </body> I hope this helps and solves the idea that you are trying to explain. Share this post Link to post Share on other sites