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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am attempting the simple task of

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
AU
I am attempting the simple task of passing a value entered in a form field to the next page so it can be dsplayed in a simple hello message.

THE CODE I HAVE TO CAPTURE THE FORM VARIBALE AND SETUP THE ADDRESS OF THE SECOND PAGE IS:

<head>
<script language=&quot;Javascript&quot;>
function selectWindow() {
var address
address = &quot;HTMLKITOUTPUT.HTM?searchfor=&quot; +
document.searchcust.searchfor.value
window.open(address,&quot;&quot;,&quot;HEIGHT=800,WIDTH=1000&quot;)
}
</script>
</head>
<body>
Customer Selection
<form name=&quot;searchcust&quot; >
<p>Search For <input type=&quot;text&quot; NAME=&quot;searchfor&quot; value=&quot;&quot;
onchange=&quot;selectWindow()&quot;>
<p>
</form>
</body>


THE SECOND PAGE TO DISPLAY THE MESSAGE IS:

<head>
<meta http-equiv=&quot;content-type&quot;
content=&quot;text/html;charset=iso-8859-1&quot;>
<title>Searching For </title>
<script language=&quot;JavaScript&quot;>
function showsearch() {
var alertmsg
alertmsg = &quot;We are searching for($searchfor)&quot;
alert(alertmsg)
}
</script>
</head>



<body onLoad=&quot;showsearch()&quot; >

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
var request = new Object();
myname = request.searchfor
</script>

Hello <script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>document.write(myname)</script>


The second page displays but the result I am getting is that the variable is undefined .

Any ideas AND THANKS !!!
 
searchfor is not defined as a variable. You have only used seachfor.value to populate part of the variable address. Define searchfor as a variable first then call it. DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Can you spoon feed me by inserting where the declaration goes as I have been tooling around for an hour without success.
 
try...

**
searchfor = document.searchcust.searchfor.value

address = &quot;HTMLKITOUTPUT.HTM?searchfor=&quot; + searchfor
**

- spewn
 
I am now getting it to the point where I have the output page opening with the address line of:
file:///D:/My%20Documents/My%20Webs/myweb/HTMLKITOUTPUT.htm?searchfor=helen
Assuming &quot;Helen&quot; was the string entered.

At this point I am stuck retreiving and displaying the string on the output page. In the showsearch function, the alert message is dipslaying as &quot;We are searching for ($searchfor)
 
As I understand the problem, you already have a correct url with parameter passed using &quot;?&quot;, and now you need to extract the value passed.
So here it is:

function searchIt() {
value = document.location.search;
value = value.substring(11, value.length);
alert(value);
}

You may call the searchIt() function like this:
<a href=&quot;javascript:searchIt()&quot;>search</a>
or any other way.

It was tested and works fine.
[tt]value.substring(11, value.length)[/tt] extracts all chars from ?searchfor=something, starting from 12th because the length of &quot;?searchfor=&quot; equals 11 chars. So alert box will show you &quot;something&quot;.

Hope this will solve the problem.
 
It worked..thanks Starway.

In the statement :
value = document.location.search;

I assume these are reserved words that will create the value based on :

Document. = the document currently loaded
Location. = the URL of the document
search = whatever is after the ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top