Click to See Complete Forum and Search --> : Travel to a Target within js code
RavenWind
01-06-2004, 12:50 AM
How can one put a line of code to move the page down to a target on a page after the script runs? Example:
<Script language="text/javascript"
Script's code here
#######
</Script>
I want to replace "#######" with a line of code that will execute lastly in the script that moves down to a Target on the same page. Is this doable, and will entries in form elements remain intact? Thanks,
Kenneth
fredmv
01-06-2004, 12:55 AM
Do you mean something like this?<script type="text/javascript">
//<![CDATA[
onload = function()
{
location = '#foo';
}
//]]>
</script>Then, somewhere else on the page:<a name="foo"></a>
RavenWind
01-06-2004, 01:05 AM
Yes, thats what i needed, but it didn't work?I'm using a variable to store the path, for example:
<Script>
var firstPath = "#target1"
Script's Coding
location = firstPath;
</Script>
Why wont this work?
Kenneth
fredmv
01-06-2004, 01:20 AM
Most likely because the element doesn't yet exist. You must execute the code somewhere after the element or in the onload event handler as I previously demonstrated.
RavenWind
01-06-2004, 01:26 AM
Ah, well, I am working within a Form, and when the user picks one radio button, it disables a range of form elements. This is where i want to add target code. See:
<script>
function example(a,b,c)
script to disable form elements (from element a to element b)
location = c
</script>
<body>
<input type=radio name="answer" Value="No" onclick="example(2,3,"#target");">
</body>
Do you see what i want? Thanks for helping,
Kenneth