SetAttribute Href - Why Wont It Work?

Sep 23, 2009

Im writing a piece of javascript that dynamically adds a link to a page, this is the code i'm using

var newP;
newP = document.createElement("a");
newP.innerHTML = "Click here";[code].........

However, it wont work?!?! the link appears in the right place on the page when i remove the line newP.setAttribute("href","http:[url]......);and if i view the source the link is <a>Click here</a> (without any href) so there's got to be something wrong with that line but i don't know what it is.I'm using firefox.

View 2 Replies


ADVERTISEMENT

IE Href Does Not Work After Js?

Nov 11, 2009

if f returns true then href gets 'executed', else not. Works in FF, GC. In IE 7 does not work. How to get this working in IE ?

<a onclick="return f();" href="../jsp/...">
function f()
{

[code]....

View 5 Replies View Related

Why Href Does Not Work With This Function

Jun 20, 2010

I've a problem with this ajax function, the url doesn't actualize. I want to see the hash in url, but with the function it's not possible. Why?The code I use in php is:

Code:

<br><a href="#nosotros" onClick="FAjax('nosotros.php' ,'capaContenedora','','get'); return false"><b>nosotros</b></a>

And the function is:

Code:

function FAjax (url,capa,valores,metodo)
{
var ajax=creaAjax();
var capaContenedora = document.getElementById(capa);

[code]...

View 9 Replies View Related

Making Single Link Work With Two HRef?

Oct 13, 2011

I have a link that has an mp3 sound as its href:<a href="sounds/genealogy.mp3" class="track track-default"> this is a link</a>. Unfortunately, I also need that same link to go to a part on the site (href=#greenhouse) so that the sound plays on that part of the site.

View 2 Replies View Related

Can't Get Window.location.href To Work In Some Browsers

Jan 31, 2005

I have this line in an XHTML form:

Code:

<input type="reset" name="cancel" value="Cancel"
onclick="javascript:window.location.href('/index.php');" />
In IE5.5 clicking the cancel button loads the index.php page fine.
In Firefox 1.0 & also the version of IE running on my IPAQ it doesn't work - clicking the button doesn't do anything.

Anyone have any ideas or alternative solutions?
I thought maybe I was using an IE only thing but it is a version of IE on the IPAQ. I thought maybe it was not standards compliant but I haven't found anyone having a similar problem.

Any idea or advice?
TIA, BG.

PS Ignore that I am using a reset button to do this - I have also tried it in the body tag like this:

Code:

<body onload="javascript:alert('Login Successfull!
You are logged into my app');window.location.href('/myapp/index.php');">

View 6 Replies View Related

Using HREF And ONCLICK In An Anchor Tag Doesnt Seem To Work

Aug 11, 2005

I'm trying to setup a page that uses JavaScript in a text link to submit a form:

<a href="do.htm" onclick="javascript:document.forms.Q01.submit();">

I also have added a fallback page in the href (do.htm) in case users have JavaScript disabled. But the JavaScript doesn't seem to be working. When I click the link it always goes to the fallback page, and doesn't submit the form.

I've tried swaping the order in the anchor tag (JS first, href second):

<a onclick="javascript:document.forms.Q01.submit();" href="do.htm">

and the same thing happens.

If I remove the href value:

<a href="#" onclick="javascript:document.forms.Q01.submit();">

the JS does execute properly.

How can I get the JS to execute by default for browsers that support it, and the href be the backup for browsers that dont support it?

View 1 Replies View Related

Does Window.location.href = Work In Firefox??

Mar 18, 2007

In my case it doesn't work. I need to transfer some variables from js to php Any work arounds???

View 5 Replies View Related

Document.write Won't Work Just After An Href Link In A Frame

Jul 23, 2005

I've got a little Quizzer program that asks a question in the upper frame of a frameset and then lists the answer in the lower frame. Answers can be plain text, straight html, a sound, or a LINK. I have a function that builds the answer frame using document.write(among other things). This code works fine until you encounter a link. It dutifully displays the link in the lower frame but the very next question builds the newContent perfectly but does NOT write it to the frame even though it appears to execute it.

if (answerType == "link")
{
parent.frames[1].location = URL;
} else {

// pitiful attempt to clear linked page
parent.frames[1].location.href = "QuizzerAnswer.htm";

var newContent = '<html><head><title>Quizzer Answer</title>'
newContent += '</head>'
newContent += '<body>'

if (answerType == "text" || answerType == "html") {
newContent += answerValue;
}

if (answerType == "sound") {
newContent += '<embed src="' + answerValue;
newContent += '" width="170" height="25" autostart="true">'
}

newContent += '</body>'
newContent += '</html>'

parent.frames[1].document.write(newContent);
parent.frames[1].document.close();
}

View 5 Replies View Related

JQuery :: Lava Lamp Href Doesnt Work?

Jan 4, 2011

Look at :[URL}...prace/2/ When you click some link the floating bar goes there but none site is opened ;/ It seams that the problem is here:

[Code]...

View 2 Replies View Related

SetAttribute + IE 6

Apr 6, 2007

this script updates an image on a page and resets the class name of a link. Works fine in Mozilla browser. However, the setAttribute method in the second function doesn't work in IE. Is there a known bug connected with this?

Any ideas?

var view;
//update image
function getView(view)
{
var source = view.getAttribute("href");
var imgsrc = document.getElementById("view");
imgsrc.setAttribute("src", source);
setClass(view);
}
// update class names of links
function setClass(view)
{
var arLinks = document.getElementsByTagName("a");
var ct = (arLinks.length-1);
for (var i=0; i<ct; i++)
{
arLinks[i].setAttribute("class", "inactive");
}
view.setAttribute("class", "active");
}

View 3 Replies View Related

JavaScript SetAttribute

Jul 23, 2005

I am struggling to write an meta element in JS. The meta element in question
is the refresh element.

This is the code I am using

//----------------
function setMetaContent(metaTag, metaName, value) {
//----------------

var metas = document.getElementsByTagName('meta');

if (debug) alert('[setMetaContent] metaTag='+metaTag+' metaName=
'+metaName+' value '+value);
for (var i=0; i<metas.length; i++) {
if (metas[i].getAttribute(metaTag)==metaName)
break;
}
if (debug) alert('[setMetaContent] i='+i+' value '+value);
metas[i].setAttribute('content',value);
}

and I call it with:

View 7 Replies View Related

Use A Variable In SetAttribute

Nov 24, 2011

How do I use a variable in setAttribute ?

View 1 Replies View Related

SetAttribute() In Opera 7.54 Win

Mar 27, 2005

I'm in the process of migrating a script to use DOM core methods but I've hit a roadblock in the aforementioned browser. The following code snippet illustrates what I'm basically trying to do, it really is incredibly basic!

var newimg = document.createElement('img');
newimg.setAttribute('id', 'placeholder');
newimg.setAttribute('src', 'images/large/courtyard.jpg');

I'm then positioning the element on the page using appendChild(). Everything works perfectly on Firefox 1, IE5+, Opera 8, Konqueror 3.3.1 (Linux) but not in Opera 7.54. I suspect the element is being created as associated styling on #placeholder is being applied (just some padding and borders) but the image itself is not being displayed. I assume therefore that the problems lies with setAttribute()?

This seems like the sort of problem that others would have encountered, but I haven't been able to find mention of it anywhere.

View 7 Replies View Related

JQuery :: Href In Output Code Causing $getJson() Function To Try To Load Up A File With Href In Url

Jul 12, 2010

I'm using the following code (simplified version) to call a Json file, parse it and on each iteration, create a div with an ID of "tab". I'm using this with jQuery UI .tab() to create a listing with entries which have three tabs. Anyhow, the principle seems to work except that when I examine what's happening behind the scenes using Firefox console, I see that each href in the html code produced is causing the Json function to re-fire using the href as it's url target.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

[Code].....

View 6 Replies View Related

SetAttribute Vs. Dot Notation -- Not The Same In FireFox?

Oct 7, 2005

I did some searching around, but didn't see this addressed directly. Here is an example of when dot notation fails in Firefox, and when SetAttribute doesn't fail: Code:

View 4 Replies View Related

AppendChild, CreateElement, SetAttribute In IE

Jul 31, 2006

this works perfectly in firefox - but in internet explorer it just creates the first lable and the input field, although it creates the input field as a regular text field instead of for files. the caption label and text field aren't created at all. any ideas? Code:

View 7 Replies View Related

I Can Not Add Onclick Property With SetAttribute On IE.

Dec 10, 2006

I am using the following code to create an 'a' element with 'texto' to add the onclick property to an object:

var vinculo = xCreateElement('a');
var nodoTexto = document.createTextNode('texto');
xAppendChild(vinculo, nodoTexto);
xAppendChild(celda2, vinculo);
vinculo.setAttribute('onclick', 'buscarSolucion(1,1,1)');

'celda2' is a table cell. This works with FF but not with IE. I solved this using a comment from here for the 'name' attribute, like this:

...
vinculo = xCreateElement('<a onClick="' + onClick + '">');
...

But I would like to put it in a function to make it general for any element that has the 'onclick' property. Is there any other way to set the 'onclick' attribute & to be understand by IE & FF?

NOTE: I also found that I can not set 'colspan', I have to set colSpan. Also, I can not set 'class' I have to use the canonical method with 'object.className=...'

View 10 Replies View Related

SetAttribute Multiple Instances

Nov 18, 2007

I know there is a problem with IE (I wont bother inserting a witty comment here) on handling:

setAttribute('onclick','doStuff');

I have found

yourAnchor.onclick = function() {
// do what you want in here.
}

this works, but I the script I am working on is going through every DIV with a certain class and adding links to the div, I want the button to change something within the div where it is located so I need to pass the id of the parent div. I thought perhaps there was someway to find the id of the button pressed?

View 5 Replies View Related

JQuery :: Error A.setAttribute Is Not A Function With 1.4.4

Nov 15, 2010

Just after upgrading from v1.4.3 to v1.4.4 I started receiving this javascript error on the console, but apart from the update, I didn't do any code modifications. If I follow the console link, it takes me to this point in the source:

[Code]...

with the line in red marked as the error source. What could it be causing the error?

View 8 Replies View Related

Weird SetAttribute('usemap',val) In Opera

Jan 7, 2007

It works OK in IE and Moz, but in Opera the change of the attribute's value works on once, first time. No error. That confuses me. Why works only once? Any ideas? Code:

View 16 Replies View Related

SetAttribute For Multiple Attributes Question

Jul 18, 2007

I have multiple attributes (class, id and title) that is needed to insert into a div together. All I know how to use setAttribute for single attribute. So the question is there an "array" setAttribute method to insert all attributes together into an element OR is there a "after" or "before" setAttribute method I can use to insert an attribute after or before other attribute?

View 2 Replies View Related

SetAttribute And Onclick Return False?

Mar 19, 2009

I want to implement:

<a href=123 onclick="javascript:return false">123</a>

in DOM,

I have:

var link = document.createElement('a');
link.setAttribute('href', 123);
link.setAttribute('onclick', 'function() { return false; }');

but it doesn't work. The reason I want a href and onclick = false is because I want to drag and drop the 123.

View 2 Replies View Related

SetAttribute Remote Window And Iframe Preload

Jun 26, 2002

I need setAttribute "src" from main windows to pop-up window (Iframe in it) and also i need to prepload all src files ONCE, so if user ever click to open pop-up and do it againt, its no need to loading againt, can anybody help with the script ... ? Or maybe can sugest me with better method to have same result.

View 3 Replies View Related

SetAttribute Works GREAT In FireFox - Ie Doesn't Like It

May 10, 2011

I've been working on this for about four hours (two today, two yesterday) and keep hitting the brick wall. I'm trying to create a function that will add an attribute to specified tags. As the title says, it works great in FF and not at all in IE7. Probably the first question you'll ask after you see my code is "why?" Well, I've got a form with over 100 form fields in it, and if I can avoid manually adding an attribute to all of them, I'll take the JS route.

[Code]...

View 5 Replies View Related

Element.setAttribute('onclick' - Setup A Form With Radio Buttons - "Object" Is Undefined Error

Jan 26, 2010

I am trying to setup a form with radio buttons. Each radio button has an OnClick event. When a radiobutton is clicked the current set of radio buttons will be replaced with a new set using document.createElement("input"). Each new radio button needs the same onclick event addedas in the initial set of radio buttons. I first tried:

element.setAttribute('onclick', MyFunction(value));

This, however, will somehow automatically trigger the onclick event! I searched on the internet and found this as the solution:

var new_onclick = function() { alert("this works!"); };
element.setAttribute('onclick', new_onclick);

This will give a "Object" is undefined error!

View 2 Replies View Related

Element SetAttribute() Method - Valid Method Of Changing The Id Of An XHTML Element

Feb 24, 2010

Is the form below a valid method of changing the id of an XHTML element, specifically the one actually being referenced? It does not seem to work for me.

document.getElementById("Original_Name").setAttribute("id", "New_name");

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved