Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any way to set the value of an input box from a separate page?

Status
Not open for further replies.

static786

Programmer
Feb 13, 2006
23
GB
I know how do do it using frames, but I'm tring to this using a different page altogethor? Can someone help?
 
You can send info from one page to another using the ? at the end of the URL. On the input page, dynamically link to the page to which you want to send the data, with something like "?myInput=this" at the end of the URL. Then you can retrieve it with Javascript in the receiving page like this:

myInput = parseInt(getValue("myInput"));

function getValue(varname)
{
// First, we load the URL into a variable
var url = window.location.href;

// Next, split the url by the ?
var qparts = url.split("?");

// Check that there is a querystring, return "" if not
if (qparts.length == 0)
{
return "";
}

// Then find the querystring, everything after the ?
var query = qparts[1];

// Split the query string into variables (separates by &s)
var vars = query.split("&");

// Initialize the value with "" as default
var value = "";

// Iterate through vars, checking each one for varname
for (i=0;i<vars.length;i++)
{
// Split the variable by =, which splits name and value
var parts = vars.split("=");

// Check if the correct variable
if (parts[0] == varname)
{
// Load value into variable
value = parts[1];

// End the loop
break;
}
}

// Convert escape code
value = unescape(value);

// Convert "+"s to " "s
value.replace(/\+/g," ");

// Return the value
return value;
}
 
if you are opening the page using javascript, or are attempting to change the field in one page in one window from another page in another window, this can also be done with javascript.

under what circumstances will you be using this functionality?



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
basically i want to set the text box on another page to a specific value, and then submit that form on that page.

This is the code I had when I was using it as a frame (instead of using it as a separate page):

<script language="JavaScript">
parent.map.document.formMap.boundarybox.value = document.PCForm.bbox.value;
parent.map.document.formMap.submit();
</script>
 
MamaGeek,

in the example you provided, you would need to remove the parseInt call, otherwise "this" would never get returned.

just an fyi...



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top