473,386 Members | 1,997 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 do I change the href property to the web anchor element

In jscript, I would like to be able to set the href attribute of the anchor
element. I have a aspnet:hyperlink button on the page, but I would like to
be able to set the href attribute of this element via jscript.

How do I do this?

I am attempting to prevent extra trips to the server. Currently, I set the
navigateurl in server side scripting, but I know the answer on the client.

Thanks

Eric
Mar 26 '06 #1
6 2076
DWS
javascript
On the server you build the clientid of the anchor right into the script or
element event that changes it.

dim x as new HTMLAnchor
controls.add(x)
dim chkItalic As New CheckBox
chkItalic.Text = "Change Href"
chkItalic.InputAttributes.Add("onclick", "changehref(""" & x.ClientID & """)")
Controls.Add(chkItalic)

<script>
function changehref(k23er) {
document.getElementById(k23er).href="helloworld.as px";
}
</script>

Good Luck
DWS

"eswanson" wrote:
In jscript, I would like to be able to set the href attribute of the anchor
element. I have a aspnet:hyperlink button on the page, but I would like to
be able to set the href attribute of this element via jscript.

How do I do this?

I am attempting to prevent extra trips to the server. Currently, I set the
navigateurl in server side scripting, but I know the answer on the client.

Thanks

Eric

Mar 26 '06 #2
Hi Eric,

As DWS has mentioend, if you have explicitly assigned an ID for the html
anchor, we can use the document.getElementById method to reference it in
client-side script.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 27 '06 #3
Hi Steven,

On the client side, I attempted to use setAttribute("href","www.msn.com");
and it appeared to fail.

Is there a difference between .href and .setAttribute?

I will try this other method.

Thanks

Eric

"Steven Cheng[MSFT]" wrote:
Hi Eric,

As DWS has mentioend, if you have explicitly assigned an ID for the html
anchor, we can use the document.getElementById method to reference it in
client-side script.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 27 '06 #4
I did the suggested command from jscript on the client, but I have to put an
alert box for the screen to see my button changes.

Here is my script:

document.getElementById("cmdViewPDF").href = "/PDF/"+
newRow.getCell(5).getValue();
alert("set href");

Only after the alert is fired does my anchor show up changed. If I remove
the alert statement, the href does not get updated.

How do I refresh the screen without the alert statement?

Thanks

Eric

"eswanson" wrote:
Hi Steven,

On the client side, I attempted to use setAttribute("href","www.msn.com");
and it appeared to fail.

Is there a difference between .href and .setAttribute?

I will try this other method.

Thanks

Eric

"Steven Cheng[MSFT]" wrote:
Hi Eric,

As DWS has mentioend, if you have explicitly assigned an ID for the html
anchor, we can use the document.getElementById method to reference it in
client-side script.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 27 '06 #5
Hi Eric,

setAttribute/getAttribute is mainly used for XML document since they're the
standard interfaces defined by the W3C DOM specification. For html
element's certain property, we should always use their name to directly
reference them. And for the new problem you mentioned, are you going to
change the displayed text or the href address of the hyperlink control
,also where do you put the script code in your page's client-side html
source, would you provide some detailed code snippet of the page?

here is my test page's clent-side code which change a hyperlink's title and
location:

=======================================
.....................

<script language="javascript">
function change_link()
{
var link = document.getElementById("HyperLink1");

link.href = "http://www.asp.net";
link.title = "ASP.NET Site";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="file" id="file1" name="file1" runat="server"
onchange="file_onchange(this);" />

<a id="link" href="." >my hyperlink</a>

......................
==============================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 28 '06 #6
use
window.document.getElementById('<id of the element>').href = "new href
value";

in javascript.

Regards,
Harshal P

"eswanson" <ej*******@newsgroups.nospam> wrote in message
news:06**********************************@microsof t.com...
In jscript, I would like to be able to set the href attribute of the
anchor
element. I have a aspnet:hyperlink button on the page, but I would like
to
be able to set the href attribute of this element via jscript.

How do I do this?

I am attempting to prevent extra trips to the server. Currently, I set
the
navigateurl in server side scripting, but I know the answer on the client.

Thanks

Eric

Mar 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christian Kusenbach | last post by:
Hello group! I've a problem with JavaScript and IMG-Objects. On my webpage I use a big image and several small images. If you click on a small image, it executes a JavaScript to change the...
4
by: Johnny | last post by:
I have a page with a button that has the following link: <a href="/somelink?org.apache.struts.taglib.html.TOKEN=ef9f9f5973be37ffe39c60227f402770#" onclick="javascript:go( event, 'myForm');return...
2
by: Heiko Pliefke | last post by:
Hi NG! I have to change dynamically all hyperlinks, when the html-page is loaded at the client. This works fine, except in the following scenario: When the innerText of an anchor contains an...
10
by: Bill H | last post by:
I used a bit of JS on a page that is fairly long and didn't like the way that <A HREF='#' ONCLICK=\"... refreshed the page to the top. Removing the HREF (<A ONCLICK=\"...) solved my...
2
by: deko | last post by:
I'm trying to change the font style of a link when that link is clicked. But the link (sometimes) includes a named anchor. So I need to test for a given named anchor and apply style changes if...
1
by: james.kingston | last post by:
I've read that one must return false from an onclick handler attached to an anchor if we wanted to prevent the browser from following the href. In a greasemonkey script I'm hacking together with...
5
by: Simon Benson | last post by:
Probably a fairly simple problem but one that's been plaguing me for a couple of days... can anyone help? I have a classic ASP page with a number of text boxes which are updatable. For...
2
by: gvrajkumar | last post by:
Hi We are developing an Ajax based application. In this application the URL is fixed and as user navigates on the application we will change Anchor on the URL so that user can bookmark the url...
2
by: Peter Laman | last post by:
In my app I need to dynamically generate a series hyperlinks. Each hyperlink's action must be to focus a field in a <form>. I created the following function to create such a link (the argument is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.