This is a discussion on Re: [PHP] A two flavored post within the PHP General forums, part of the PHP Programming Forums category; On 10/4/07, tedd <tedd@sperling.com> wrote: > > Hi gang: > > I asked this ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On 10/4/07, tedd <tedd@sperling.com> 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"> 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 |
|
|||
|
At 11:18 PM -0400 10/4/07, Nathan Nobbe wrote:
>On 10/4/07, tedd <<mailto:tedd@sperling.com>tedd@sperling.com> 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 |
|
|||
|
On 10/5/07, tedd <tedd@sperling.com> wrote:
> At 11:18 PM -0400 10/4/07, Nathan Nobbe wrote: > >On 10/4/07, tedd <<mailto:tedd@sperling.com>tedd@sperling.com> 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 > > Tedd, try this (it's also live and working at http://www.crusar.org/test.php): <? $s = $_GET['s']; ?> <script language="JavaScript"> function writeHREF(value,title) { var url = "http://www.crusar.org/test.php"; var currentTime = new Date(); var month = currentTime.getMonth(); var day = currentTime.getDate(); var year = currentTime.getFullYear(); var jsvalue = month + '/' + day + '/' + year; document.write('<a href="' + url + '?s=' + value + '&jsvalue=' + jsvalue + '">' + title + '</a>'); } </script> This is where your JS link will appear, Tedd: <script language="JavaScript"> writeHREF('<?=$s;?>','Test Link'); </script> -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 Give a man a fish, he'll eat for a day. Then you'll find out he was allergic and is hospitalized. See? No good deed goes unpunished.... |
|
|||
|
This might be a way to do it:
*Example 1* <script> function appendMeBaby(aVar){ self.location.href = 'img.php?s=' + aVar + '&someOtherVar=itIsMeTheValue'; } </script> <a href="javascript:appendMeBaby(<?php echo($value);?>);">Click here</a> *Example 2* <script> function appendMeBaby(aVar, bVar){ self.location.href = 'img.php?s=' + aVar + '&someOtherVar=' + bVar; } </script> <a href="javascript:appendMeBaby(<?php echo($value);?>, 'itIsMeTheOtherValue');">Click here</a> Hope this helps Aleksandar Daniel Brown wrote: > On 10/5/07, tedd <tedd@sperling.com> wrote: > >> At 11:18 PM -0400 10/4/07, Nathan Nobbe wrote: >> >>> On 10/4/07, tedd <<mailto:tedd@sperling.com>tedd@sperling.com> 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 >> >> >> > > Tedd, try this (it's also live and working at > http://www.crusar.org/test.php): > > <? > $s = $_GET['s']; > ?> > <script language="JavaScript"> > function writeHREF(value,title) { > var url = "http://www.crusar.org/test.php"; > var currentTime = new Date(); > var month = currentTime.getMonth(); > var day = currentTime.getDate(); > var year = currentTime.getFullYear(); > var jsvalue = month + '/' + day + '/' + year; > document.write('<a href="' + url + '?s=' + value + '&jsvalue=' > + jsvalue + '">' + title + '</a>'); > } > </script> > > This is where your JS link will appear, Tedd: > <script language="JavaScript"> > writeHREF('<?=$s;?>','Test Link'); > </script> > > > > |
|
|||
|
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@sperling.com> wrote: > > At 11:18 PM -0400 10/4/07, Nathan Nobbe wrote: > >On 10/4/07, tedd <<mailto:tedd@sperling.com>tedd@sperling.com> 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 > > |
|
|||
|
On Fri, 2007-10-05 at 19:19 +0200, Aleksandar Vojnovic wrote:
> This might be a way to do it: > > *Example 1* > <script> > function appendMeBaby(aVar){ > self.location.href = 'img.php?s=' + aVar + > '&someOtherVar=itIsMeTheValue'; > } > </script> > <a href="javascript:appendMeBaby(<?php echo($value);?>);">Click here</a> > > *Example 2* > <script> > function appendMeBaby(aVar, bVar){ > self.location.href = 'img.php?s=' + aVar + '&someOtherVar=' + bVar; > } > </script> > <a href="javascript:appendMeBaby(<?php echo($value);?>, > 'itIsMeTheOtherValue');">Click here</a> I don't believe that is standards-compliant use of the href attribute. Also it doesn't degrade gracefully for people who have JavaScript disabled. Cheers, Rob. -- .................................................. .......... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! .................................................. .......... |
|
|||
|
At 12:58 PM -0400 10/5/07, Daniel Brown wrote:
> ><? >$s = $_GET['s']; >?> ><script language="JavaScript"> >function writeHREF(value,title) { > var url = "http://www.crusar.org/test.php"; > var currentTime = new Date(); > var month = currentTime.getMonth(); > var day = currentTime.getDate(); > var year = currentTime.getFullYear(); > var jsvalue = month + '/' + day + '/' + year; > document.write('<a href="' + url + '?s=' + value + '&jsvalue=' >+ jsvalue + '">' + title + '</a>'); >} ></script> > >This is where your JS link will appear, Tedd: ><script language="JavaScript"> > writeHREF('<?=$s;?>','Test Link'); ></script> Daniel That's slick. I solved the problem by using: <a href="img.php?i=<?php echo($value);?>" onclick="window.location = this.getAttribute( 'href' ) + '&s=' + s; return false;"> But, I am sure I will be using your's sometime soon. Thanks, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
At 1:26 PM -0400 10/5/07, Nathan Nobbe wrote:
>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: Not that I provided information otherwise, but document.getElementById won't work in this case because there are several links involved. As such, I have to use document.getElementByClass and that has problems. Unfortunately, my solution isn't unobtrusive. <a href="img.php?i=<?php echo($value);?>" onclick="window.location = this.getAttribute( 'href' ) + '&s=' + s; return false;"> However, I couldn't see a way to make it so. Many thanks for your time and effort. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
On Sat, 2007-10-06 at 13:41 -0400, tedd wrote:
> At 1:26 PM -0400 10/5/07, Nathan Nobbe wrote: > >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: > > Not that I provided information otherwise, but > document.getElementById won't work in this case because there are > several links involved. As such, I have to use > document.getElementByClass and that has problems. > > Unfortunately, my solution isn't unobtrusive. > > <a href="img.php?i=<?php echo($value);?>" onclick="window.location = > this.getAttribute( 'href' ) + '&s=' + s; return false;"> > > However, I couldn't see a way to make it so. Why not? I'm guessing because you need to the link to have the JavaScript variable in it. If this is the case then the href target should link to a page informing the user that they need to have JavaScript installed. By doing so you inform them of why clicking on the link is not having the desired outcome :) Cheers, Rob. -- .................................................. .......... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! .................................................. .......... |
|
|||
|
At 1:49 PM -0400 10/6/07, Robert Cummings wrote:
>On Sat, 2007-10-06 at 13:41 -0400, tedd wrote: > > Unfortunately, my solution isn't unobtrusive. >> >> <a href="img.php?i=<?php echo($value);?>" onclick="window.location = >> this.getAttribute( 'href' ) + '&s=' + s; return false;"> >> >> However, I couldn't see a way to make it so. > >Why not? I'm guessing because you need to the link to have the >JavaScript variable in it. If this is the case then the href target >should link to a page informing the user that they need to have >JavaScript installed. By doing so you inform them of why clicking on the >link is not having the desired outcome :) > >Cheers, >Rob. Rob: I would agree with you IF I was creating a web page for the general public. However, what I am creating in my laboratory is a monster of my own making that will be used only by my clients AND those clients will be required to have javascript turned on. Sometimes, programming for the lowest common denominator limits possibilities. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
![]() |
| Thread Tools | |
| Display Modes | |
|
|