JavaScript - Print The Id Of A Link When Clicked?
Hi everyone! I need a little help with something. I have a page with several links that when clicked open a modal window. The same window for each link, with a form. However inside the form I need to print the id of the link that was clicked. Like so:
<a href="#" id="1">Link 1</a> <a href="#" id="2">Link 2</a> <a href="#" id="3">Link 3</a> <form> ....somehow print/echo the id of the link... </form> Is this possible? Does anyone know how to do that? I'd appreciate any help! Similar TutorialsSorry I am new to JavaScript. Says that a.html has two same anchor links (<a href="b.html">b</a>). The anchor links are uneditable but we could add JavaScript to the a.html. Except for dynamic adding onclick event, any other ways could get to know which anchor link being clicked? Hello I need to not publicly display phone number inside my website page (I use Joomla CMS). In fact the main goal is of course to be able to show the number but not to be crawled by search engine.. So in practice instead to see this: Phone: 013456789 I would like to see this: Phone: Click here for see the number By clicking on that link the number must be displayed... My website for display the phone field use this php code: Code: <?php echo $CustomFields->field('my_phone',$listing); ?> I asked in some forum and some people tell me is possible to customize this php code with javascript for let me hide/show the field value but I don't have a single idea how to do this because I'm not a programmer... I take a look in all javascript libraries but I don't find any javacript ready for use for let me implement it inside the php code... Anybody have a suggestion please ? many thank I have no clue if this is in the correct forum but.... is there a way to determine whether a user clicked on a link vs typed in the url to get to a page? I'm trying to stop users from messing with GET forms (and i have to use them, POST wouldn't make sense in this case). Thanks I have a WebHelp framework created by chmProcessor whereby index.htm calls frameset.html that references a left frame "treeFrame" and right frame "frameCont". The treeFrame has javascript to change the icons from selected to not selected and high light the selected topic. I have a need to have links in the right frame. And when I click on the link in the right frame, I want the right frame to display the topic but I also want the treeFrame navigation to open the navigation to the newly selected topic. How would I go about implementing this? In the tree.html, the tree navigation gets created with this code: Code: contentTree.create( document.getElementById( "contentsTree" ) , window.parent.document.getElementById( "frameCont" ) , window.parent.parent.location.href ); Here is the tree.js Code: /************************************ (C) Toni Bennasar 2007 http://chmprocessor.sf.net Under GPL license. Functions to create a content tree for many web pages. *************************************/ var contentTree = new Object(); contentTree.pageloaded = function() { // Get the title of the loaded page: pageRelativeUrl = getPageTitle( contentTree.frame.contentWindow.document.location.href ) // Search the link to this page node = contentTree.seachLinkByHref( pageRelativeUrl ); if( node == "" ) { // Try to search by the page title, without internal reference: idx = pageRelativeUrl.indexOf( "#" ) if( idx >= 0 ) pageRelativeUrl = pageRelativeUrl.substring( 0 , idx ); node = contentTree.seachLinkByFileTitle( pageRelativeUrl ); } if( node != "" ) { // If its found, select it over the tree: contentTree.selectLink( node , true , false ); } } // Initializes the tree. // tree : UL element that contains the tree // frame: The frame that will contain the topic pages. // url: Input URL of the page. contentTree.create = function( tree , contentFrame , url ) { // Store ref to tree elements: contentTree.frame = contentFrame; contentTree.tree = tree; contentTree.selectedLink = ""; // Change the links to open his ref into the iframe contentTree.links = tree.getElementsByTagName("a"); // Create click events for the links: for (var i=0; i<contentTree.links.length; i++) { contentTree.links[i].onclick = function(e){ contentTree.frame.src = this.href; contentTree.selectLink( this , false , true ); //e.stopPropagation(); stopEvent(e); return false; } } // Prepare all the submenus var submenus = tree.getElementsByTagName("ul"); for( var i=0; i< submenus.length; i++ ) { var sb = submenus[i]; sb.parentNode.className="submenu"; sb.setAttribute("status", "closed"); // click open the submenu: sb.parentNode.onclick = function(e) { var ulChild=this.getElementsByTagName("ul")[0]; if( ulChild.getAttribute("status") == "closed" ) { contentTree.openUlElement( ulChild ); } else if( ulChild.getAttribute("status") == "open" ) { ulChild.style.display="none"; ulChild.setAttribute("status", "closed"); this.style.backgroundImage="url(1g.gif)"; } //e.stopPropagation(); stopEvent(e); } // To avoid events when the submenu items are pressed. sb.onclick=function(e){ //e.stopPropagation(); stopEvent(e); } } // Load the default page, or the selected topic page: var topic = getURLParam( url , "topic"); var topicLink = ""; if( topic != "" ) topicLink = contentTree.seachLinkByTitle( topic ); if( topicLink != "" ) contentTree.selectLink( topicLink , true , true ); else if( contentTree.links.length > 0 ) contentTree.selectLink( contentTree.links[0] , true , true ); // When an internal link is clicked follow the selection at the tree: contentFrame.onload_1 = function(){ contentTree.pageloaded(); } } contentTree.openUlElement = function( ulElement ) { if( ulElement.getAttribute("status") == "closed" ) { ulElement.style.display="block"; ulElement.setAttribute("status", "open"); ulElement.parentNode.style.backgroundImage="url(2g.gif)"; } } contentTree.selectUrl = function( url ) { var lnk = contentTree.seachLinkByHref( url ); if( lnk == "" ) // URL not found contentTree.frame.src = url else contentTree.selectLink( lnk , true , true ); } contentTree.selectLink = function( lnkObject , expandTree , loadContentFrame ) { if( contentTree.selectedLink != "" ) contentTree.selectedLink.style.backgroundColor = contentTree.notSelectedBg ; else contentTree.notSelectedBg = lnkObject.style.backgroundColor; if( loadContentFrame ) contentTree.frame.src = lnkObject.href; contentTree.selectedLink = lnkObject; lnkObject.style.backgroundColor = "#33CC66" ; if( expandTree ) { var ulElement = lnkObject.parentNode.parentNode; while( ulElement != contentTree.tree ) { contentTree.openUlElement( ulElement ); ulElement = ulElement.parentNode.parentNode; } } } // Search a link into the tree by his text: contentTree.seachLinkByTitle = function( strTitle ) { var strTitleLower = strTitle.toLowerCase() for (var i=0; i<contentTree.links.length; i++) { // Get the text of the link, without return carriages var linkText = contentTree.links[i].innerHTML.toLowerCase(); linkText = linkText.replace(/\n/," "); linkText = linkText.replace(/\r/,""); if( linkText == strTitleLower ) return contentTree.links[i]; } return ""; } // Search a link into the tree by his href: contentTree.seachLinkByHref = function( strHref ) { for (var i=0; i<contentTree.links.length; i++) { //var aux = unescape( contentTree.links[i].href ); var aux = contentTree.links[i].href; if( aux == strHref || endsWith( aux , "/" + strHref ) ) return contentTree.links[i]; } return ""; } contentTree.seachLinkByFileTitle = function( strFile ) { for (var i=0; i<contentTree.links.length; i++) { //var aux = getPageTitle( unescape( contentTree.links[i].href ) ); var aux = getPageTitle( contentTree.links[i].href ); if( aux == strFile ) return contentTree.links[i]; else { idx = aux.indexOf( "#" ) if( idx >= 0 ) { aux = aux.substring( 0 , idx ); if( aux == strFile ) return contentTree.links[i]; } } } return ""; } // Search links that contains contentTree.searchByContent = function( strSearch , idList , idTopicsList ) { var list = document.getElementById( idList ); list.options.length=0; if( strSearch == "" ) return; var topicsList = document.getElementById( idTopicsList ); //var strLower = strSearch.toLowerCase(); var strLower = normalizeString( strSearch ); for (var i=0; i<topicsList.options.length; i++) { if( normalizeString( topicsList.options[i].text ).indexOf( strLower ) >= 0 ) { var opt = new Option( topicsList.options[i].text ); opt.value = topicsList.options[i].value ; list.options[ list.options.length ] = opt; } } list.ondblclick = function(e) { if( list.selectedIndex >= 0 ) contentTree.selectUrl( list.options[ list.selectedIndex ].value ); } } Hey all, Hoping someone could help me out with some javascript coding as I am a complete novice to this! I am currently building a website using 1 static page and all the content will be pulled in through different iframes by clicking on a navigation on the page. I found a very handy piece of javascript coding that lets me remove a class from one link and move it to the link that was clicked on (the code will be below). The issue I am facing with this is that if I have Home set to class="On" to begin with and then click on Location, the background image will be added to the Location section but won't get removed from Home until it is physically clicked on. Can anyone help me out with how I can get this to work correctly? javascript: Code: <script language="JavaScript" type="text/javascript"> var Lst; function CngClass(obj){ if (typeof(obj)=='string') obj=document.getElementById(obj); if (Lst) Lst.className=''; obj.className='On'; Lst=obj; } </script> HTML: Code: <div id="navWrapper"> <div id="globalNav"> <ul> <li onclick="CngClass(this);" class="On"><a href="iframes/home.html" target="content_iframe">Home</a></li> <li onclick="CngClass(this);" class=""><a href="iframes/location.html" target="content_iframe">Location</a></li> <li onclick="CngClass(this);" class=""><a href="iframes/speakers.html" target="content_iframe">Speakers</a></li> <li onclick="CngClass(this);" class=""><a href="iframes/agenda.html" target="content_iframe">Agenda</a></li> <li onclick="CngClass(this);" class=""><a href="iframes/useful_material.html" target="content_iframe">Useful Material</a></li> <li onclick="CngClass(this);" class=""><a href="iframes/event_presentations.html" target="content_iframe">Event Presentations</a></li> <li onclick="CngClass(this);" class=""><a href="iframes/gallery.html" target="content_iframe">Gallery</a></li> </ul> </div> <div id="localNav"></div> </div> Hi guys, I've been breaking my brains for few hours, I already searched online and I found nothing so far. What I wanna do.... I have 5 different images linked to 5 different websites. Once the image is clicked, the first link will be displayed in an iframe, and the image will change to the second one. Once we click on the second image, the second link will be displayed using the same iframe, and so on. The code changes the images,but I dunno how to deal with the link to the websites. This is the code: Code: <html> <head> <title>Testing...</title> </head> <script type="text/javascript"> imgs=Array("1.png","2.png","3.png","4.png","5.png"); links=Array("www.vbct.ca","www.cnn.com","www.castanet.net","www.yahoo.com","www.cubaweb.cu"); var x=0; function change() { document.getElementById("changes").src=imgs[++x]; if (x==4) { x=-1; } } if (!imgs[x+1]) { x=-1; } </script> <body> <div> <iframe src="http://www.vbct.ca" style="border: 0; position:relative; top:0; left:0; right:0; bottom:0; width:100%; height:400px;" name="page" width="100%"></iframe> </div> <br /><br /> <div> <a href="#" target="page"><img src="1.png" id="changes" alt="alttext" onmousedown="change()" style="cursor: pointer;" /></a> </div> </body> </html> And this is the link to the test page: http://www.virtualbc.ca/sites/test/ <script language="JavaScript"> function changeColor(cell_id){var state1="#dde6ed"; var state2="#ffc20e"; var cellid = new Array ("id1", "id2", "id3", "id4", "id5", "id6"); for(var i = 0; i < cellid.length; i++){var nav = document.getElementById(cellid[i]); if(cellid == nav.id){nav.style.backgroundColor=state2;} else {nav.style.backgroundColor=state1;}}} </script> Can anyone tell me what is wrong with this script. I put an onClick= changeColor(this);" in my <td> tag to call the script but still not working. Hey, I'm not to good at javascript and need help. When someone clicks an option in a <select> box, I want a field to appear with a normal text box. For example: Code: <!--Option box--> <select name="method"> <option>Post 2 Host</option> <option>Paid</option> <!--I want it when they click Paid, a box shows up below. Such as--> <input type="text" name="paid" /> Can you show me how I can do this? Thanks. Hey, I'm new to javascript and was wondering if there is something where you can tell if something is clicked. All I need is to know something where you click something and it appears, and click again it disappears. How can I do this? Thanks! I have a simple problem that I can't solve. I know that you guys might know how to solve it. I'm using an extension of dreamweaver called Coursebuilder. I'm making an online-examination to improve education especially in a far region of Asia where there's poor quality of education in there. Now, I'm making a multiplication choice type of exam with radio buttons in it and when the "check answer" was clicked, the answer will be explained. It is already done, but the problem is the feedback score. I can't make a feedback score... example the examination is 40/100 score it must appear on the screen at once after a click of a certain button. That's my only problem for now. It will be used in CD format and online. what should i do? All I need is to know how will I put a button that once it was clicked the score in the examination will appear. I'm an amateur web designer, I need your help. Thanks please help me. On custom button images, how do you give them the effect that they're "pushed" when the user clicks them and "unpushed" when the user lets his finger off the mouse button? I'm guessing it's some type of rollover effect, but I'm not sure how it's done.
Hi everyone - I was wondering how it would be possible for me to create a FAQ with drop-down answers when the question is clicked? For example: https://www.facebook.com/help/?page=1145 Facebook has something like that available. Any ideas? Hi, I am currently working on a website with a custom livesearch. The livesearch is a simple <ul> under the input box. I am trying to make it so that if the user click anywhere other than the input box(id=searchInput) or the list(id=searchResults). I tried an onblur on the input box, but when the user clicks on the list it vanishes, which defeats the object! Any help would be much appreciated I know that this can be done using .hide/.show... I don't know how to say this but if you'll look at the code: Code: <div id="isclickable"> klasdlkasdklaklsjd <div id="weeeee"> trolololololol </div> </div> <div id="isclickable"> klasdlkasdklaklsjd <div id="weeeee"> trolololololol </div> </div> The div having an id of "weeeee" will show if id="isclickable" is clicked.. but not all divs having "weeeee" should show but instead what is inside the div "isclickable" is there a way to attain this without creating multiple scripts and ids? Thanks> I want to show the div when a button is clicked. And the div will enter the page by sliding in (from the left of the page). When it got clicked again, the div will dissapear by sliding out from the page. Any suggestions? Thank You. Hey all, I would like to get the id of a html check box when the client clicks it. I want to do this on the client side so i need to use java script. I want to be able to do this in both fire fox and ie window.event.srcElement works great for ie but not for firefox please do not tell me to use Event.target for firefox because that does not work. At least it is not working for me anyway. Thanks Hello, I am just going through my javascript book and looking/learning at examples. I've copied this code and i'm thinking i could really use this in my site, it's something i've been looking for on the internet for a while. I have a few questions regarding certain things and I would like to slightly change the code so it performs an additional task. I have uploaded a live example of the page as it is a lot easier for you guys to help and also easier for myself to explain properly. The file is located he JS test page. As you can see, you click the different tabs and the relative information comes up. 1)How can I change the code so that if one description is currently on-screen, when another tab is clicked, i want to hide the currently displayed information, and show the relative information to that particular tab. 2)As you can see, clicking the tabs just brings up text saying 'Description for Tab' + #. This is added using the DOM, but i want to add a lot of description and obviously do not want to put an awful lot of text into the function. What is the best way to add this content dynamically? Should I create an XML file and access this file using javascript to display the different information? I understand question 2 could be done using ajax and php but I know nothing about either so i was wondering if there was another way to achieve this? Thank you for your time, Regards, LC. I have a javascript for a tree view but i need to change it according to the requirement. Lets start with example with the treeview as follow: 1 Door phone 1.1 Ready Kits 1.1.1 Audioset 1.1.2 Videoset 1.2 Audio Kits 1.2.1 Elphone 1.2.2 Video Door phone 2 CCTV 2.1 Camera 2.1.1 Dome Camera 2.1.2 IP Camera 2.2 Others Now the thing is in the current treeview a single category is open at a time. like if 1.1.1 is open 1.1.2 will b closed and similarly if 1.1 is open...1.2 will b closed. But i want that when i click on 1(Door phone) ie Door phone...evry node should be opened instead of just one similary when i click on 2(CCTV), all its node should be opened. I hope it will be possible to achieve this and i would be helped. I can also provide with the javascript if required. Can a checkbox do 2 different things after it is clicked? Right now I am using this... Code: <input type="checkbox" onclick="processCheckbox(this);"> <input type="checkbox" onclick="activLink(this.checked)"> I don't want to have 2 checkboxes on my page, just 1 and get the same result. Is this possible? Chad Hi, I have an "offline" html demo of 50+page - so it needs to run on standard html/javascripts... I'm trying to do this: Page A Code: <a href="pageb.html?endpage=pageD.html">Page B.html</a> <a href="pageb.html?endpage=pageE.html">Page B.html</a> <a href="pageb.html?endpage=pageF.html">Page B.html</a> Page B Code: <a href="PageC.html?endpage=(the parameter of page A)">Page C</a> <a href="(the parameter of page A)">End Page</a> Page C Code: <a href="(the parameter of page A)">End Page</a> I've searched for a couple of hours already and I just can't seem to find this... I'm not that great at javascripts... Thanks a lot! |