473,396 Members | 1,940 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,396 software developers and data experts.

Simple Javascript replace (with a twist!) of an href

Hey, I posted this yesterday, but no one had any ideas? C'mon now, I
know this isn't that hard, i'm just a little new to javascript, and I
can't quite figure this out. I searched and searched to try and find
the answer to this, but I had no luck anywhere. It's a little
different situation than I found anywhere else. I would simply put
javascript into the <a> tag, but like I said, It's delivered via PHP,
and I don't have access to it. I could really, really, really use your
help here.

Here's what I posted yesterday, (sorry for the repeat, but I really
need some help here) :

<begin quote>
Ok, so I need to change the href of a link on our php driven auction
calendar. what I need to do is change the href in the "More Info"
button link from "auction_detail.php?ID=91582" to
"http://www.primetimeauctions.com/auctions/2006_auctions/koseris_real_estate/Koseris
Estate.shtml"

I do not have access to the template or scripting that supplies the
html, and whoever designed it used the same name for similar div's,
i.e. EVERY more info button on the page has a div id of
"listMoreButton". So I can't reference the exact div and change it's
href. The reason I need to do this is that the html parser used by our
hosting company is retarded, does not work correctly. look at
http://www.primetimeauctions.com/auc...l.php?ID=91582 to see
what it does, and
http://www.primetimeauctions.com/auc...isEstate.shtml
to see what it's supposed to look like. Where I have that page already
in place and functioning correctly, I would rather just change the link
on the More Info button using JS than make them fix their html upload
utility (because they won't).

We have a sitewide global.js that executes onLoad. it does a variety
of things, and the function(s) i have written to do this simple change
do not work. Here is the code i have :

function kswap() {
var srch = "auction_detail.php?ID=91582";
var replc =
"http://www.primetimeauctions.com/auctions/2006_auctions/koseris_real_estate/KoserisEstate.shtml";
/*if (document.getElementById(listMoreButton).href == srch)
{document.getElementById(listMoreButton).href = replc}*/

for (var i=0; i<(document.links.length); i++)
{
if (document.link[i].href == srch)
{document.link[i].href = replc;}
}

}

The commented out seciton was how i originally tried to get this to
work, but there are multiple div's with that id (listMoreButton).

I have spent hours searching and testing with no luck. I couldn't find
anyone in a situation similart to mine. Any help would be appreciated.
If there is any way to change the href of a link delivered through php
with a sitewide javascript that executes on page load, please help
point me in the right direction.
<end quote>

Like I said, it shouldn't be that difficult, but its killing me and
eating up time that I need to be spending on other things. Another
idea I had would be a simple text based search and replace done with
java. I don't need this scripting to be "smart", I just need it to
blindly replace one literal string (that happens to be an href, buried
in html, delivered by php) with another string. If there is a more
simple, literal string replacement is possible, fine with me...just
point me at the code.

Thanks Again,
Evan

Mar 28 '06 #1
2 8347
Hi,

While I can't be sure, I'd expect you'd get more responses if your
messages didn't have length on the order of a book. You might also
want to avoid offending people by calling things retarded. Everyone
else is wondering why you're doing this with javascript since it means
that your page will be inaccessible to a significant number of people.
You'd be better off messing with the php. Anyway, so you're left with
me :)

One problem is that you're assuming the href coming from
document.links[i].href is relative like it is in the HTML. These are
fully expanded, so it'll be something like
http://www.whatever.com/...yourfile.php. You're testing for an exact
match - use a regular expression.

-Jeff

Mar 28 '06 #2
Ok, thanks everyone.

I changed document.link to document.links (i had done this before, i
just was experimenting with other things and didn't catch that), and
also changed my search from a relative link to a fully expanded link
like Jeff said to do. I got it working, sorry if I offended anyone,
but it can be frustrating when simple things like this eat up so much
time.

Thanks Again!

Mar 28 '06 #3

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

Similar topics

12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
2
by: OM | last post by:
I need a simple Javascript shopping cart. I did a few searches on Yahoo... And got a few results of free Javascript shopping carts. The problem is there tooo complicated and very hard to...
4
by: Owen Parker | last post by:
Hi all I am not a java programmer but i can hack at it a bit. I am trying to allow a user to define the text in a simple javascript text scroller. The data is stored as multiple records in a...
9
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE...
3
by: Brad | last post by:
I see the use of Javascript replace all over the web. What are all the character sequences? (sorry I am a bit of a newbie at this). i.value.replace(/+/g, ''); I understand that /g is global...
1
by: Random Task | last post by:
Can someone help me by providing an example of how to replace / with \ in a string in xslt2. The characters / and \ seem to cause me grief ... I am trying the below code currently ... Any...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
2
by: Yi | last post by:
I want to make a simple javascript widget, something looks like the Google AdWords, that people can just post a small section of code on their web page and display some content from my website. ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.