Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

How "autofill" A Form Field?


2 replies to this topic

#1 emperor

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 105 posts
  • Location:Sala Bolognese

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 (:lol: the field F1 will contain "choice 2".
I hope that you have understand my explanation.

#2 Tyssen

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,161 posts
  • Location:Brisbane, QLD

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 theRealSheep

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 69 posts
  • Location:Australia

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'.
<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


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users