Solved

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

Posted on 2004-08-11
18
161 Views
Last Modified: 2010-04-06
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
Comment
Question by:groone
  • 7
  • 7
  • 2
  • +1
18 Comments
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
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
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
0
 
LVL 4

Accepted Solution

by:
kolpdc earned 500 total points
Comment Utility
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
 
LVL 3

Author Comment

by:groone
Comment Utility
Pinaldave, huh?

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

0
 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
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
 
LVL 3

Author Comment

by:groone
Comment Utility
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
 
LVL 3

Author Comment

by:groone
Comment Utility
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
 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
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
 
LVL 3

Author Comment

by:groone
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
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
 
LVL 3

Author Comment

by:groone
Comment Utility
same error.  Checking link.
0
 
LVL 3

Author Comment

by:groone
Comment Utility
okay, I had to call the form first and then call the script.  Let me test it in the real application
0
 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
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
 
LVL 2

Expert Comment

by:phpisthefuture
Comment Utility
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
 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
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
 
LVL 2

Expert Comment

by:phpisthefuture
Comment Utility
>>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
 
LVL 3

Author Comment

by:groone
Comment Utility
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
 
LVL 4

Expert Comment

by:kolpdc
Comment Utility
you're welcome. have fun.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now