• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Transfer data of a hyperlink to a form on a different page

I've got two html files.  One is named Send and the other is named Receive.  Receive has a text box on it named myField.  Send has a link that is trying to populate myField.  It's not working.  How do I get it to work?  I want myField to have the value of the hyperlink ?myField=333333.  Here are copies of the very basic html codes.  So when receive.htm pops up it has 333333 in the text box.

=================Send======================
<html>
<head>
<title>Send</title>
</head>
<body>
<a href="receive.htm?myField=333333">This is my test</a>
</body>
</html>
==========================================

================Receive=====================
<html>
<head>
<title>Receive</title>
</head>
<body>
<input type="text" name="myField" size="20"></p>
</body>
</html>
==========================================
0
groone
Asked:
groone
  • 7
  • 7
  • 2
  • +1
1 Solution
 
pinaldaveCommented:
Hi groone,

you may need server side language to do this. like in cold fusion

<input type="text" name="myfield" size="20" value="#url.myfield#">

Regards,
---Pinal
0
 
pinaldaveCommented:
0
 
kolpdcCommented:
if you'd have to frames, you could directly access the other frame by javascript. but i don't think you want.
you like to call receive.htm. am i right?

so use javascript within receive.htm to get the url. then split the url into the several parts. if you have your id, just set your textbox (you know it's name) to the id.
i try to provide you the script, but i am not able to test it, so there can be errors. just try it.

<SCRIPT LANGUAGE="JavaScript">
<!--
   var ID;

   function getID() {
       var sID;
       var sURL = window.location.href;
       var iPos  = -1;

       iPos = sURL.lastIndexOf("=");
       sID  = sURL.substring(iPos + 1, sURL.length());

       document.myField.value = sID;
   }

   getID();
//-->
</SCRIPT>

take a look here (helpful)
http://de.selfhtml.org/javascript/objekte/index.htm
http://de.selfhtml.org/javascript/objekte/string.htm
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
grooneAuthor Commented:
Pinaldave, huh?

kolpdc, I cannot edit the receive.htm form as it is a static form at a paging company's website.

0
 
kolpdcCommented:
then it will get a little bit difficult, if i understood you right. if you know its structure, you could, for example, create your own receive.htm and send its values to the script that processes the original receive.htm.
so create your own receive.htm with the same named html-form, the same fields and - with a little bit of luck - it does not require a sessionkey or something like that and you can send your own data. but that's not a nice way.
0
 
grooneAuthor Commented:
I found something like this, but I wonder if there is a way to send to another page if I do make my own and name the form.  

===========================
<a href=javascript:void(document.forms.myForm.myField.value='3333333')>Test</a><br>

<form method="POST" name="myForm">
  <p><input type="text" name="myField" size="20"></p>
</form>
===========================

See the problem exists in that the file I am editing is in asp.  I know nothing of asp except enough to know how to trace it and locate what I am looking for.  I found the variable I need and know how to hyperlink it, but beyond that I am clueless.  What this asp file does is pull information from an sql database and creates a list.   One of the fields is that of a pager number - <%=FP_FieldVal(fp_rs,"PAGERNUMBER")%>.  I was thinking that I could somehow do something like

<a href=javascript:void(document.forms.myForm.myField.value='<%=FP_FieldVal(fp_rs,"PAGERNUMBER")%>')>Test</a> but somehow have it fill the form on the other page.  Yes, I can make another form identical in structure to the one we are trying to use.
0
 
grooneAuthor Commented:
and yes, I am wanting to make the pagernumber a link so when they click on it, the number will bring up the form and the number will automatically be lsited in the pager form.
0
 
kolpdcCommented:
so if the extern page you want to address does not have a security-mechanism like a hidden session-id or something like that, you can duplicate the extern page so you can access them. just leave the address the form of the extern page calls to process the way it is.
then fill the form of the copied page with the data you want to fill in and submit the form. then the extern form-process-script should process your request.

but do not forget: if you are not directly allowed to do this, trying this could mean trouble...
0
 
grooneAuthor Commented:
Okay, I have got this able to work
<!--
   function getID() {
       var sID="";
       var sURL = window.location.href;
       var iPos  = -1;
       var iLength = 0;
       iPos = sURL.lastIndexOf("=");
       iLength = sURL.length
       sID  = sURL.substring(iPos + 1, iLength);
       return(sID);
       //document.forms.testForm.myField.value = sID;
   }
   getID();
//-->
it returns the var just fine and can be tested with a document.write function.  This part
 document.myField.value = sID;
I can't seem to get working no matter what I do.  There error I get says that "document.myField is null or not an object"

I think if can fix this problem then my problem is solved.
0
 
kolpdcCommented:
i mad a mistake. forgot about the form-object.

try document.myForm.myField.value

check http://de.selfhtml.org/javascript/objekte/elements.htm if required
0
 
grooneAuthor Commented:
same error.  Checking link.
0
 
grooneAuthor Commented:
okay, I had to call the form first and then call the script.  Let me test it in the real application
0
 
kolpdcCommented:
take a look at this: http://de.selfhtml.org/javascript/objekte/elements.htm#value
the "document.write(document.Testform.Browser.value);" is interesting. give your textfield a default-value in html-code. then try to modify the script from the last sentence. so you can play with the object-hierarchy to get the right result. if it works, use it instead of document.myForm.myField.value.
(assuming the document.myform is in the same html-document!)
0
 
phpisthefutureCommented:
The answer is very easy with PHP, let me know if your server supports PHP then I can send you the code. And also your page will be much more stable without frames. Frames always cause a problem with different browser type.
0
 
kolpdcCommented:
frames are not the best possibility, i think, too. but sometimes you need them because design forces you. if you try to avoid javascript-code specially created my one if the big browserbuilders and orientate to the standard, there is no problem.

if you do use client-side javascript or server-side php normally does not matter. if the remote-side changes its processing-script you are lost either by this way or by this way. only advantage direct advantage (in my eyes): php cannot get switched off by a user at client-side like javascript. but that's no problem, too. just give your users a hind, that javascript is to be enabled to use the page correctly.

but phpisthefuture, how would you do? send send.htm's data to your php-script, get the post-variables and resend them post to the remote-script? could you give a hint?
0
 
phpisthefutureCommented:
>>how would you do? send send.htm's data to your php-script, get the post-variables and resend them post to the remote->>script? could you give a hint?
Yes this is exactly how I would do that. Ok I went ahead and created a page for this (to give the basic idea).
Field name is f1, user input will be manipulated with the php script;
------------------------------------------------------------------------------------------------------------
<?php
if ($submit) {         //If form submit button pressed
   $f1 = $_POST['f1'];   //Call the input from the text field
   $f1 = "<table><tr><td width=100%>".$f1."</td></tr></table>";   //Output the f1 text field  
   $f1htm = str_replace("<","&lt;",$f1);   //here's the html source code output
}
else {
}
?>
-------------------------------------------------------------------------------------------------------------
I am little bit confused with the wording of the question so I have created two alternatives;
First one; User input will be generated at the right side, and html source will be give below in the text area.
http://www.freeauctionscripts.com/crosspromotion/index5.php
Second one: User input will be generated (also adds a default URL value) and html source will be generated below.
That's what I understood from link.
http://www.freeauctionscripts.com/crosspromotion/index4.php
So you have $f1 and $f1htm variables to use wherever you like. You can send it to another page/server and manipulate it for your needs. It is almost 4 in the morning and if I am not clear enough please let me know, and if you need further description/code I will send tomorrow, please ask.
Good luck
0
 
grooneAuthor Commented:
thank you much kolpdc.  The final script looked like this, no frames necessary -

<SCRIPT LANGUAGE="JavaScript">
<!--
   function getID() {
       var sID="";
       var sURL = window.location.href;
       var iPos  = -1;
       var iLength = 0;
       iPos = sURL.lastIndexOf("=");
       if (iPos > 0) {
          iLength = sURL.length
          sID  = sURL.substring(iPos + 1, iLength);
          document.forms.emailform.recipient.value = sID;
          return false;
          }
   }
   getID();
//-->
</SCRIPT>
0
 
kolpdcCommented:
you're welcome. have fun.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now