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

using javascript to rewrite current page

Status
Not open for further replies.

49er

Programmer
Aug 24, 2000
38
US
I have a page with a select box that offers 3 choices. Based on the user's choice, I want to rewrite the current page with a document.write statement. Is this possible? My code with the error line highlighted is below. Thanks alot!!!!

if (searchBy == "Address") {
var 2ndStageContent
2ndStageContent = (&quot;<html><center><font size='2'>I want to search by: </font></td>&quot;);
2ndStageContent += <select size='1' name='SearchDistanceList'>&quot;);
2ndStageContent += (&quot;<script language=javascript>&quot;);
2ndStageContent += (&quot;var searchCriteria = new Array(1);&quot;);
2ndStageContent += (&quot;searchCriteria[0] = '5 minute walk (1/2 mile)';&quot;);
2ndStageContent += (&quot;searchCriteria[1] = '10 minute walk (3/4 mile)';&quot;);
2ndStageContent += (&quot;for (var i = 0; i <= 2; i++) {&quot;);
2ndStageContent += (&quot;document.write ('<option value=' +searchCriteria + '>' + searchCriteria);&quot;);
******** THE NEXT LINE IS THE PROBLEM **************
2ndStageContent += (&quot;</script>&quot;);
***************************************************
2ndStageContent += (&quot;}&quot;);
document.write(2ndStageContent);
}
[sig][/sig]
 
within and document.write statements in javascript use \/ so

2ndStageContent += &quot;<\/script>&quot;;

also, you don't need the parentheses around each of you 2ndStageContent lines (only in the document.write statement).

later, [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
Please note that if you don't enclose code in
Code:
tags, unclick the 'Process TGML' button at the bottom when posting. Certain parts of your code will be interpreted as special markup characters. Your code became italicized because TGML interprets as an italics tag, thus removing it from view and replacing with HTML <I> tags. [sig][/sig]
 
A further point is that your </script> tag is written within your for (....) function - shold read as follows:-

Code:
2ndStageContent += (&quot;for (var i = 0; i <= 2; i++) {&quot;);
2ndStageContent += (&quot;document.write ('<option value=' +searchCriteria[i] + '>' + searchCriteria[i]);&quot;);
2ndStageContent += (&quot;}&quot;);
2ndStageContent += (&quot;</script>&quot;);
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top