473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to locate a on a web page according to parameter submitted with a form

I have a wab page with pattern :
[HTML]<a name="a">a</a>
<a name="b">b</a>
<a name="c">c</a>
<a name="d">d</a>
<a name="e">e</a>
[/HTML]
i put anchor links to be able to locate on every item.
And at the top of the page i have a form including only a textbox and a submit button. now what i want to do is either with javascript or something else, locate on the item which has the anchor name value equal to the string which is entered by the user to the forms textarea. anybody can help me ??
thanks everybody a lot
Aug 20 '07 #1
7 1350
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

You can access the anchor by adding a # before the name:
Expand|Select|Wrap|Line Numbers
  1. var dest = document.getElementById('txtAreaID').value;
  2. location.href='#'+dest;
Aug 20 '07 #2
i add the code you give and it work but with a little problem. when i type p and click submit the page locates to the anchor with the name property p but relocates to the top of the page again suddenly. i couldn't fix the problem here is the code of my page. please help. thank you.

[HTML]<script language="javascript">
function locate()
{
var dest = document.getElementById('text1').value;;
location.href='#'+dest;
}
</script>

</head>

<body>

<form name="form1">
<input type="text" name="textfield" id="text1"/>
<input type="submit" name="Submit" value="GO" onclick="locate()"/>
</label>
</form>
<br/>
<br/>
<br/>
<br/>
<br/><br/>
<br/>
<br/><br/>
<br/>
<br/>
<a name="a">a</a><br /><br />
<a name="b">b</a><br /><br />
<a name="c">a</a><br /><br />
<a name="d">a</a><br /><br />
<a name="e">a</a><br /><br />
<a name="f">a</a><br /><br />
<a name="g">a</a><br /><br />
<a name="h">a</a><br /><br />
<a name="i">a</a><br /><br />
<a name="j">a</a><br /><br />
<a name="k">a</a><br /><br />
<a name="l">a</a><br /><br />
<a name="m">a</a><br /><br />
<a name="n">a</a><br /><br />
<a name="o">a</a><br /><br />
<a name="p" id="p">p</a><br /><br />
</body>
</html>[/HTML]
Aug 20 '07 #3
acoder
16,027 Expert Mod 8TB
Please use CODE tags when posting code. Thanks!

This might have something to do with the fact that you're setting the id of "p" too.
Aug 20 '07 #4
i remove the id tag but it still has the same problem. does it works in your browser? if so that means my browser (ie6) has problems with the script and i gotta do something, if not please help me.
Aug 20 '07 #5
Logician
210 100+
i add the code you give and it work but with a little problem. when i type p and click submit the page locates to the anchor with the name property p but relocates to the top of the page again suddenly. i couldn't fix the problem here is the code of my page. please help. thank you.
You are submitting the form, which causes the page to reload. Use
Expand|Select|Wrap|Line Numbers
  1. <input type=button ....
or return false in the onclick handler.
Aug 21 '07 #6
thank you all for your help. it's working now.
Aug 21 '07 #7
acoder
16,027 Expert Mod 8TB
Glad you got it working. Post again if you hit a problem.
Aug 21 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: wk6pack | last post by:
Hi, I have a problem and not quite how to go about solving it. I have a form written in asp. I wish to submit the form and have the server return back to the same page without actually...
2
by: J Krugman | last post by:
I have a form with a couple of submit buttons, plus a "pseudolink" that is also supposed to submit the form; the submitted form data feeds to a CGI script. The two submit buttons have the name...
2
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely...
2
by: Ben Turner | last post by:
Hi, I need to create an ASPX page that includes both traditional HTML Forms (which are submitted to a third-party site like a travel booking service) and also make use of the ASP.Net form. I've...
7
by: Tom wilson | last post by:
I have created a very simple example that doesn't work. Form1 contains a textbox and a button: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
16
by: whyyyy | last post by:
The script below works fine if the form is filled out and submitted. But a (blank) e-mail is sent whenever the page loads, even when the form is not submitted. I would like to receive the e-mail...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.