By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

how do I change the href property to the web anchor element

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.