JavaScript - Quick Q For A Javascript Master. Add Variable To Hyperlink Instead Of Text
Hi,
I need to replace "Link Text" with the value in the variable (myNewString). myNewString is just text e.g hello code document.write(myNewString); <a href="welcome.html">Link text</a> i need some thing like the below or even a php version of it <a href="welcome.html">(myNewString)</a> THANKS!!!!!!!!! Similar TutorialsHey all, I'm sure this is very basic but I'm having a hard time adding a hyperlink to text within javascript. I want to add a website link to the text 'click here' that is being displayed under the image within javascipt. I end up modifying the whole image instead, removing the javascript that displays the larger version of the image. Can anyone help me out please? Here's the coding. I'm using Dreamweaver CS5 on a PC to modify a few things and using another website building program to get the basic layout. I'm just a small business owner trying to get my website off the ground. Thanks in advance! <div id="imCel1_01"> <div id="imCel1_01_Cont"> <div id="imObj1_01"> <a href="javascript:imShowBox('files/june2011.jpg',500,500,'Right click to print....................Click HERE for website!','IMG','t');" title=""><img src="images/p025_1_01.jpg" alt="" title="" /></a> </div> I have this code but it doesnt work: Code: <script type="text/javascript"> var number = 10; document.getelementbyid(number).value = number; </script> <input type="text" id="number" value=""> Can anybody help me out here? Basically what we are trying to accomplish is this... We have a php file in which a hyperlink "Select Forms" is present. What we want to happen is when the "Select Forms" link is clicked on a pop-up window will open. The content of this window is generated from our database and displayed for the user. The php in this window generates a list of checkboxes for the user to select and an "OK" button. What we want to happen is when the user selects the various checkboxes and clicks "OK" the window closes and the previous "Select Forms" link is converted to text based on the checkboxes selected from the pop-up window. We have the pop-up window already taken care of, as well as the php codes. We are having a hard time getting the php variables for the checkboxes transferring to the previous window and converting that link to the text variables. Any ideas? Thanks!! Is it possible to create a text hyperlink with 2 different font colours in one word e.g. Hyper link so that the colours swap over when the mouse is placed over any part of the link i.e.. Hyper link . ? Using #FF6600 for orange and #006600 for green and by setting the css as follows: .graph a:link { color:#FF6600; text-decoration: none; } .graph a:visited { color:#FF6600; text-decoration: none; } .graph a:active { color:#FF6600; text-decoration: none; } .graph a:hover { color:#006600; text-decoration: none; } and then by applying a javascript rollover using a span inside the link I have been able to make one side of the link behave as desired, but not both sides. <span class="graph"><a title="graph" href="vml/patterdale-swirral-edge.htm">Hyper<span class="grn" id="span1" onmouseover="this.style.color='#FF6600'" onmouseout="this.style.color='#006600'">link</span></a></span> I would prefer to use just css, but a solution with javascript would be equally appreciated. Hello everyone, Here's the scenario I wish to plan out. I have an index.htm page ready. I want to be able to put in javascript code into the HTML coding that will write the ip address of the actual server that is hosting the website into a hidden text box. Then I want to insert this ip address into a hyperlink in the original index.htm to link to another html page (this will be a SSL secure page instead i.e. https://<ip address>). Also vice versa. (With SSL index.htm page have code that writes ip into hidden text box then hyperlink to the original http index page) thanks. Hope you follow me Edit: Problem solved.
I've been hammering at this for quite a while and it has me stumped. I have 4 variables that I am creating in the head section of my code. I am passing 2 parameters to my test page via the url and they are intended to be used to construct alternate url's for use by menu buttons. This my test url. My test link Here is a code snippet that creates the alternate url's. Code: <script type="text/javascript"> var videofile = swfobject.getQueryParamValue('id'); var af = swfobject.getQueryParamValue('af'); function enLink() { var enLink = "http://jim.playourvideo.net/lsatest.htm?id=" + videofile + "&af=" + af; alert(enLink); } function spLink() { var spLink = "http://jim.playourvideo.net/lsatest.htm?id=sp" + videofile + "&af=" + af; alert(spLink); } function grLink() { var grLink = "http://jim.playourvideo.net/lsatest.htm?id=gr" + videofile + "&af=" + af; alert(grLink); } function frLink() { var frLink = "http://jim.playourvideo.net/lsatest.htm?id=fr" + videofile + "&af=" + af; alert(frLink); } </script> I am trying to call the appropriate function by clicking on one of menu buttons. When I click any of the buttons I get an alert showing that my url is properly constructed. But the link never seems to fire and result in switching video files. I did also try it with onclick - same result. What should happen is the page should reload and play a different regionally captioned file. For testing I haven't captioned the test files. Just trying to get the logic working. I'd sure appreciate some advice. Jonni I'm not that familiar with classic ASP or Javascript but need to change an exisiting program to do the following: Add a link to a page but only for certain marketers. I have a classic ASP page that has a couple of hyperlinks for each marketer that is selected from a combobox drop down. The new hyperlink is to be added but only for select marketers. The rest don't even get to see this new hyperlink. I added a function in Javascript as such: Code: function IsPikeESCO(UID,UCD) { var strTemp; var mktrno,mktname; var frm; var IsPike; IsPike = false; frm = document.Downloads; strTemp=frm.MKTRACCT.options[frm.MKTRACCT.selectedIndex].text; mktrno=strTemp.substring(0,10); switch (mktrno) { case 8: IsPike = True; break; case 99: IsPike = True; break; case 162: IsPike = True; break; } return IsPike; } Now I need to check if True then display the hyperlink, so I came up with this, which I know is not correct: Code: <tr><td></td><td <%IF <a HREF="javascript:IsPikeESCO('<%response.write request("passUID")%>','<%response.write request("passUCD")%>')" = True THEN%> onMouseOver="/orradata/pike.DAT">Pike Data</font></a> <%END IF%> I want to be able to check the fuction for each marketer and if return is TRUE, then produce the hyperlink which will open a data file if clicked. Can someone help? I'm not sure how to use the <%IF statement in conjunction with a javascript function that checks for a return value, and based on that return value, does some action. I am new to java and tried writing the code for practice but it doesn't seem to work <html> <Head> <title>Discount</title> <script language ="Javascript"> <!-- function CalculateBalance(numItems,totPrice,discount) { var balance; balance = (1 - discount)*totPRice; alert ('Your balance is $'+balance +' Thank You.'); document.write("<br>YOu bought "+ numItems+" items for $"+totPrice); document.write("<br>Your balance is $"+ balance+" your discount was"+discount*100+"% Thank you"); } //--> </script> </head> <script language ="Javascript"> <!-- var discount; var numItems = parseInt(prompt('HOw many time did you buy [ >=12 is 20% and >= 6 is 10% discount]',"0")); alert ('You bought '+numItems +' items.'); document.write("You bought "+ numItems+" items."); var totPrice = parseFloat(prompt('The total price that you paid was',"0.0")); if(numItems >= 12) {discount = .2;} else if (numItems >=6) {discount+ .1} else {discount = 0;} CalculateBalance(numItems,totPrice,discount); //--> </script> </html> It only prints to the screen the number of items I bought I am working on a site for an online radio station and I want an external player to launch on site visit and to continue playing as the visitors surf my site. I feel I am 95% there as I have the player spawning on launch and checking for popup blockers. If a popup blocker is found the user is prompted to add my domain to their allowed lists so that future visits will launch the player right out of the box. My problem is this. When someone navigates back to the "home" page (where the script is located the external player window reloads and I do not want it to. I have found a couple of sites that say do this and that but I am a 100% novice at javascript and can not figure it out. here is the url of the site I am building http://www.radiotrips.com/czmradio - If you have popup blocker on you should get an alert. If not a small player should launch here is the code that I am using to spawn the external player and check for popup blockers ************** <script language="javascript" type="text/javascript"> function detectPopupBlocker() { var czmTest = window.open("http://www.radiotrips.com/czmradio/player/mini/no_ads.html","Cozumel Radio","width=478,height=260"); if (!czmTest) { alert("We were unable to automatically open the Cozumel Radio Player due to your pop-up blocker... Please add CozumelRadio.net to your allowed sites for your best listening experience"); } else { window.open("http://www.radiotrips.com/czmradio/player/mini/no_ads.html","Cozumel Radio","width=478,height=260"); } } ************** if anyone could add the code that would make the browser check to see if this window is already open and if so not reload it I would GREATLY appreciate it. I feel like it is 1 to 2 lines of code max according to what I have seen elsewhere but just cant figure it out. Thanks a Million in advance Chris I put the jquery script into my subdirectory. In the header which one is correct: Code: <script type="text/javascript" src="../jquery/jquery.js"></script> or Code: <script src="../jquery/jquery.js"></script> And there is this code: do I put this in the body and enclose it with the <script>tag? Code: $(function(){ // set interval for 5 minutes setInterval(function(){ $.ajax({url: "keep-alive.php"}); }, 300000); }); I have a twitter widget at this side http://1905.gs/blog on the right sidebar. At the bottom of the widget there is the follow me link. I would like to embed a follow me "button" which I have created the script for: The button script: <a href="https://twitter.com/1905GS" class="twitter-follow-button" data-show-count="false" data-lang="tr">Takip et: @1905GS</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> And here is the current javascript link: http://www.1905.gs/blog/wp-content/p...tter-widget.js How I am trying to make it look like: http://a1202.hizliresim.com/u/d/2nryy.jpg thank you very much for your help, more or less when a user has a command pop up in this prompt they are asked to type another item from a list with an okay or cancel at the bottom how do i stop the script if a user hits cancel and move onto the calculation step and by pass the other imput prompts? sorry if this isn't the clearest, i am new at javascript. THanks in advance. I need someone to make a small modification to this javascript code: <script type = "text/javascript"> function hyperlink() { var url = (location.href) url = url.replace(/\.(html)/i, "_2.html") window.location.href = url; } </script> Here is the situation: On this webpage: http://tehcake.com/video/30rock/2x14%20-%20Copyx.html where it says "Backup Links 1 2", if you click on the "1" in "Backup Links 1 2" it goes to this webpage, which is what it is supposed to do: http://tehcake.com/video/30rock/2x14%20-%20Copyx_2.html However, on this webpage, where it says "Backup Links 1 2", if you click on the "1" in "Backup Links 1 2" it leads to a non existing page by adding an extra "_2" to the end of the file name. Anyways, I need a way to modify this code (same one as above): <script type = "text/javascript"> function hyperlink() { var url = (location.href) url = url.replace(/\.(html)/i, "_2.html") window.location.href = url; } </script> This script subtracts ".html" and adds "_2.html" to the URL. Anyways, i need to change it so that if the filename has an _2.html in the file name, like in this URL: http://tehcake.com/video/30rock/2x14%20-%20Copyx_2.html the script would not add an extra _2 to the URL, instead it would just link to the same page. I dont know much about javascript so I need help to make this change. Hi, Ever seen on the iphone where you have to slide the slider across the screen to unlock it? I have a duplicate of this using javascript but no matter what I try I cannot make it redirect. I want the page to be redirected after the slider has gone to the other side. Heres the HTML Code: <!DOCTYPE html> <head> <meta charset='UTF-8'> <title>Slide To Unlock</title> <link rel='stylesheet' href='css/style.css'> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script> <script src='js/slidetounlock.js'></script> </head> <body> <div id="page-wrap"> <div id="well"> <h2><strong id="slider"></strong> <span>slide to unlock</span></h2> </div> </div> </body </html> And the javascript Code: $(function() { $("#slider").draggable({ axis: 'x', containment: 'parent', drag: function(event, ui) { if (ui.position.left > 550) { $("#well").fadeOut(); } else { // Apparently Safari isn't allowing partial opacity on text with background clip? Not sure. // $("h2 span").css("opacity", 100 - (ui.position.left / 5)) } }, stop: function(event, ui) { if (ui.position.left < 551) { $(this).animate({ left: 0 }) } } }); // The following credit: http://www.evanblack.com/blog/touch-slide-to-unlock/ $('#slider')[0].addEventListener('touchmove', function(event) { event.preventDefault(); var el = event.target; var touch = event.touches[0]; curX = touch.pageX - this.offsetLeft - 73; if(curX <= 0) return; if(curX > 550){ $('#well').fadeOut(); } el.style.webkitTransform = 'translateX(' + curX + 'px)'; }, false); $('#slider')[0].addEventListener('touchend', function(event) { this.style.webkitTransition = '-webkit-transform 0.3s ease-in'; this.addEventListener( 'webkitTransitionEnd', function( event ) { this.style.webkitTransition = 'none'; }, false ); this.style.webkitTransform = 'translateX(0px)'; }, false); }); Ok javascript gurus, could someone help me out with a simple script? I have an array that I want to loop through and display the values of the array on the page as it loops (so I guess there should be a slight delay before the next one appears over it). I want to loop though until a button is clicked. Help? Is it possible to have an input that points to some other function? For example: Code: function someFunction() { alert('It worked.'); } function doAnotherFunction(doIt, otherFunction) { if (doIt == true) { otherFunction(); } } <input type="button" value="test" onClick="doAnotherFunction(true, someFunction());"> Or would I need a switch statement and have all the various functions hardcoded? Hi! I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function. I need to send this variable as the value of a hidden field in the form which is in the body of the document. This is my JavaScript Code: Code: function WriteContactFormStatement1 () { var ContactFormValue = ref2; document.write('<input type="hidden" name="UReferrersName" value="' + ContactFormValue + '" />'); } var WriteContactFormStatement = WriteContactFormStatement1 (); And at the end of my form, before the submit button, I have the following code: Code: <!-- START -- Javascript to print the statement for UReferrersName --> <script language="JavaScript" type="text/JavaScript"> //WriteContactFormStatement(); document.write (WriteContactFormStatement); </script> <!-- End -- Javascript to print the statement for UReferrersName --> When I execute the form, it doesn't work the way it should, plus, gives me a word "undefined" next to the "Submit" button ..... Please help !... - Xeirus. I have a website at: http://www.zionism101.org/defaultfornow.aspx The page works on Google Chrome, Mozilla Firefox, and IE-9. It sort-of works on IE-8, however, the problem is that on IE-8, there is about 2 seconds where everything is shown on top of everything else in a mess. This is bad. The website is unusual in that it uses a menu to slide screens from right to left. This has implications. For instance, I need the menu to appear on all screens, so I use absolute positioning, and then use javascript to calculate the center position. The same goes for a logo image. And on top of that, some screens (which are really DIVs) have items positioned by absolute and relative positioning within them, and those positions are often calculated via javascript (and then set). On IE-8, the result is not good. I think what is happening is that the browser first shows everything as it appears before javascript is run, and then slowly the javascript is run, which puts everything in the correct position. So initially, not only is everything in the wrong position, but different DIVs appear on top of each other. I could tell every user to get IE-9 or chrome, but thats not a good solution. Thanks, Gid P.S. one solution might be to make the screen go black for an instant, until everything has settled down. If thats the only solution, how would I do that? P.P.S. there are actually 3 pages in the site: the login page, the logout page, and the founders page. Everytime the user switches between them, the jumble for 2 seconds occurs. As of right now I have a code that will work in IE but wont work in FireFox...go figure. Basically what I want to have happen is when you type in an area code it will provide an output in a predetermined area of the page. For Example: Input- 512 Output - Austin, TX The code that I have doesn't work with firefox and I was just wondering if there was a code that would allow that to happen. Thanks! |