I hope that you have understand my explanation.
| |
|
Welcome to KnowledgeSutra - Dear Guest | |
How "autofill" A Form Field?
Started by emperor, May 22 2005 08:18 AM
2 replies to this topic
#1
Posted 22 May 2005 - 08:18 AM
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.
I hope that you have understand my explanation.
#2
Posted 22 May 2005 - 08:50 AM
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";
}
?>
">
#3
Posted 25 May 2005 - 03:09 PM
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'.
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).
I hope this helps and solves the idea that you are trying to explain.
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.
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














