Re: [PHP] A two flavored post



strange; i missed that when i put it together; my bad, it was late.
here is a revision that works.

<html>
<head>
<script type="text/javascript">
window.onload = function() {
var someLink = document.getElementById('someLink');
someLink.href += "&anotherVar=8";
alert(document.getElementById('someLink').href);
}
</script>
</head>
<body>
<a id="someLink" href=" http://somesite.com?a=5";>
click here
</a>
</body>
</html>

the problem was the local variable was being assigned the value of the
attribute, not the reference
to the tag in the dom. i have now set it to be a reference to the variable
in the dom.

-nathan

On 10/5/07, tedd <tedd@xxxxxxxxxxxx> wrote:

At 11:18 PM -0400 10/4/07, Nathan Nobbe wrote:
On 10/4/07, tedd <<mailto:tedd@xxxxxxxxxxxx>tedd@xxxxxxxxxxxx> wrote:

Hi gang:

I asked this question on the javascript list, but for some reason
it's taking forever to post there. So, I figured that I would ask
here as well.

I'm currently sending data (the value of s) to another script via the
html statement:

<a href="img.php?s=<?php echo($value);?>">Click here</a>

However, I need to add another variable, namely a javascript
variable, to the GET string.

How can I send both a php and a javascript variable together at the same
time?


the question is when is the variable you want to append available to
the javascript.
as soon as you get the variable in the javascript the next thing you
can do is append
it to the value of the href attribute of the <a> tag.

<html>
<head>
<script type="text/javascript">
window.onload = function() {
var someLinkHref = document.getElementById
('someLink').href;
someLinkHref += "&anotherVar=8";
alert(someLinkHref);
}
</script>
</head>
<body>
<a id="someLink" href="
<http://somesite.com?a=5>http://somesite.com?a=5";>
click here
</a>
</body>
</html>

if you want to use the onclick event handler as rob suggested, you
could stash the variable in the Window global object, then reference
it in the implementation of the onclick function (though i still
have mixed feelings about that approach [the Window object part that
is]).

-nathan

-nathan:

Your example worked very well to provide an alert showing exactly
what I needed to be in the href string. However, it didn't work to
actually alter the actual link href string -- even when I commented
out the alert. IOW, it remained:

<http://somesite.com?a=5>http://somesite.com?a=5

instead of:

<http://somesite.com?a=5>http://somesite.com?a=5&anotherVar=8

I like the idea of keeping the code unobtrusive and working as it did
-- I just need it to work as a link.

Any ideas? This is so close.

Cheers,

tedd


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Relevant Pages

  • Re: FAQ Topic - I have window.status="Moomin"; why doesnt the statusbar change?
    ... setStatus('a JavaScript call'); ... function init() { ...
    (comp.lang.javascript)
  • Re: Can one include data from javascript in form
    ... The Beat JavaScript Editor - Ajax Editor ... <HEAD> ... JavaScript can take the contents of an HTML order form, process them, and display the order for verification even including the grand total! ...
    (microsoft.public.frontpage.programming)
  • Re: Button with onClick inside Form (with Submit Button)
    ... A DOCTYPE declaration is required here. ... be declared HTML 4.01 Transitional, for it is not Valid HTML 4.01 Strict yet. ... it must be the child element of the `head' ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Re: javascript
    ... You can't add Javascript to the head. ... Most scripts will function outside the head section. ... I'm> trying to insert html for a fading slideshow and a gallery. ...
    (microsoft.public.publisher.webdesign)
  • Security holes in Hotmail, Yahoo, and other webmails
    ... Most webmails services and applications have huge security holes on the ... execution of malicious javascript and HTML code ... some parts of the user's mailbox, without use of javascript. ... Cross-site scripting vulnerabilities on the yahoo.com domain was reported ...
    (Vuln-Dev)