JavaScript - Onclick Variable Issues
So ill try best to describe what im doing,
I grab information from a database and it displays with its model number and a value. I use that value to put into a URL so it will go to the database and delete that values entry. It works excpet it ALWAYS grabs the last value(aka the last entry). So i need it to grab what ive selected rather than the last value. Any help will be great! Code: <form name="addswitchtype" id="addswitchtype" action="<?php echo $this->url('system/switch_management/newtype'); ?>" method="POST"> <h4>Update Switch Model Information</h4> <table> <select name"switchtypeid" id="switchtypeid"> <option value="">New</option> <?php foreach($this->switchtype as $switch_type): ?> <option value"<?php echo $switch_type->switchtypeid; ?>"><?php echo $switch_type->switchmodel; ?></option> <?php endforeach; ?> </select> </table> <div id="switchtype-data" style="padding-top: 10px;"></div> <input type="submit" name="submit" value="Add Switch Type" /> <input type="button" value="Delete Switch" onclick="javascrip:document.location.href='<?php echo $this->url('system/switch_management/building/switch/' . $switch_type->switchtypeid . '/deletetype'); ?>'" /> <tr> </form> Similar TutorialsI am trying to use an onclick statement to go to an alternate web page displaying a different version of tha file being displayed in the current page. In the HEAD section of the current page I have a global variable named currentfile that contains a file name. This function is also in the HEAD section immediately below the variable's declaration Code: function altlink() { gotolink = "http://www.mydomain.com/testpage.htm?alt=" + currentfile; return gotolink } I have tried every combination I can think of in the onclick code to get it to work but, no joy. here is an example: Code: <a href="#" onClick=altlink(); return false; <img src="change.png" width="47" height="30"></a> If anyone here can sort me out I'd really appreciate it. I just can't get the next page to load. I'm doing a school project and I am using JPlayer as a media player. The site is essentially a music jukebox with a search. I have the playlist set up in the jukebox with 5 songs from the start, but I need to make it so that when you do a search and click the plus sign button next to a song, it will change one of the songs in the playlist to that song. I have the search and everything working but when I click the button it does not actually change the variable in the javascript. Any help or insight to this would be much appreciated. Below is the javascript (with some PHP, but that shouldn't effect what I need). Thanks in advance!! Code: <link rel="stylesheet" href="stylesheets/style.css" type="text/css" /> <!-- CSS files required for JPlayer --> <link type="text/css" href="skin/jplayer.blue.monday.css" rel="stylesheet" /> <link rel="stylesheet" href="skin/jplayeraudio.css" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.jplayer.min.js"></script> <script type="text/javascript"> <!-- var nextSet = 1; <?php $songsInDB = 70; $rand1 = rand(1, $songsInDB); $rand2 = rand(1, $songsInDB); while($rand2 == $rand1) { $rand2 = rand(1, $songsInDB); } $rand3 = rand(1, $songsInDB); while($rand3 == $rand2 || $rand3 == $rand1) { $rand3 = rand(1, $songsInDB); } $rand4 = rand(1, $songsInDB); while($rand4 == $rand3 || $rand4 == $rand2 || $rand4 == $rand1) { $rand4 = rand(1, $songsInDB); } $rand5 = rand(1, $songsInDB); while($rand5 == $rand4 || $rand5 == $rand3 || $rand5 == $rand2 || $rand5 == $rand1) { $rand5 = rand(1, $songsInDB); } ?> var var1 = <?php echo $rand1; ?>; var var1artist = '<?php echo $database->getSongArtist($rand1); ?>'; var var1title = '<?php echo $database->getSongTitle($rand1); ?>'; var var2 = <?php echo $rand2; ?>; var var2artist = '<?php echo $database->getSongArtist($rand2); ?>'; var var2title = '<?php echo $database->getSongTitle($rand2); ?>'; var var3 = <?php echo $rand3; ?>; var var3artist = '<?php echo $database->getSongArtist($rand3); ?>'; var var3title = '<?php echo $database->getSongTitle($rand3); ?>'; var var4 = <?php echo $rand4; ?>; var var4artist = '<?php echo $database->getSongArtist($rand4); ?>'; var var4title = '<?php echo $database->getSongTitle($rand4); ?>'; var var5 = <?php echo $rand5; ?>; var var5artist = '<?php echo $database->getSongArtist($rand5); ?>'; var var5title = '<?php echo $database->getSongTitle($rand5); ?>'; var playItem = 0; $(document).ready(function(){ var myPlayList = [ {name:var1artist+" - "+var1title, mp3:"music/"+var1+".mp3"}, {name:var2artist+" - "+var2title, mp3:"music/"+var2+".mp3"}, {name:var3artist+" - "+var3title, mp3:"music/"+var3+".mp3"}, {name:var4artist+" - "+var4title, mp3:"music/"+var4+".mp3"}, {name:var5artist+" - "+var5title, mp3:"music/"+var5+".mp3"}, ]; // Local copy of jQuery selectors, for performance. var jpPlayTime = $("#jplayer_play_time"); var jpTotalTime = $("#jplayer_total_time"); $("#jquery_jplayer").jPlayer({ ready: function() { displayPlayList(); playListInit(false); // Parameter is a boolean for autoplay. }, ended: function() { playListNext(); }, swfPath:"/js", nativeSupport: true, supplied: "mp3" }); $("#jplayer_previous").click( function() { playListPrev(); $(this).blur(); return false; }); $("#jplayer_next").click( function() { playListNext(); $(this).blur(); return false; }); function displayPlayList() { $("#jplayer_playlist ul").empty(); for (i=0; i < myPlayList.length; i++) { var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>"; listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>"; $("#jplayer_playlist ul").append(listItem); $("#jplayer_playlist_item_"+i).data( "index", i ).click( function() { var index = $(this).data("index"); if (playItem != index) { playListChange( index ); } else { $("#jquery_jplayer").jPlayer("play"); } $(this).blur(); return false; }); } } function playListInit(autoplay) { if(autoplay) { playListChange( playItem ); } else { playListConfig( playItem ); } } function playListConfig( index ) { $("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current"); $("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current"); playItem = index; $("#jquery_jplayer").jPlayer("setMedia", myPlayList[playItem]); } function playListChange( index ) { playListConfig( index ); $("#jquery_jplayer").jPlayer("play"); } function playListNext() { var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0; playListChange( index ); } function playListPrev() { var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1; playListChange( index ); } }); function loadSong(songID, artist, title) { if(nextSet == 1){ var1 = songID; var1artist = artist; var1title = title; nextSet++; } else if(nextSet == 2){ var2 = songID; var2artist = artist; var2title = title; nextSet++; } else if(nextSet == 3){ var3 = songID; var3artist = artist; var3title = title; nextSet++; } else if(nextSet == 4){ var4 = songID; var4artist = artist; var4title = title; nextSet++; } else if(nextSet == 5){ var5 = songID; var5artist = artist; var5title = title; nextSet++; } if(nextSet > 5){ nextSet = 1; } alert("Song has been queued! "+nextSet) } var i = 1; $(document).ready(function(){ $(".search").click(function(){ $.post("livequery.php", { keywords: $(".keywords").val(), mode: $(".mode").val() }, function(data){ $("table#content").empty() $.each(data, function(){ var _class = "search_content1"; if(i % 2 == 0) { _class = "search_content2"; } $("table#content").append("<tr class='"+_class+"'><td class='trunc_table' width='4%'><input type='button' value='+' onClick=\"loadSong('"+this.id+"', '"+this.artist+"', '"+this.title+"')\" /></td><td class='trunc_table' width='27%'>" + this.title + "</td><td class='trunc_table' width='1%'> </td><td class='trunc_table' width='22%'>" + this.artist + "</td><td class='trunc_table' width='1%'> </td><td class='trunc_table' width='16%'>" + this.album + "</td><td class='trunc_table' width='1%'> </td><td class='trunc_table' width='14%'>" + this.genre + "</td><td class='trunc_table' width='1%'> </td><td class='trunc_table' width='13%'>" + this.mood + "</td></tr>"); i++; }); }, "json"); }); }); --> </script> Also, the code for the playlist is in the myPlayList array, which I'm referencing the title, artist, and filename with the javascript values. I'm trying to change them in the function loadSong(songID, artist, title). I get the alert popup that I have in there, but no values change as far as the songs. I have a form, that when the user click Submit, I need a php variable to be echoed to the page. This is for an upload page. So when they are waiting for the file to upload, it will say "Uploading..." until the upload is complete. All I know so far is I need to create a javascript function and include it in the submit button. This is all I have so far in the submit button tag: onClick="Transferring();" Now I need to figure out the code to include in this function. Any ideas? I'm trying to make a basic rss reader with a google reader-esque functionality of clicking on article names and being able to expand/collapse that article. I'm working on the expand part and am going crazy. I am having no trouble getting content and displaying it without the onclick function but when I try to integrate onclick I can just get the titles. here's the snippet. any help? Code: <!-- HTML --> <body> <div id="feeddiv"></div> <script type="text/javascript"> // feed stuff using Google Feed API function feedLoaded(result) { if (!result.error) { // Grab the container we will put the results into var container = document.getElementById('feeddiv'); container.innerHTML = ''; // Loop through the feeds, putting the titles onto the page. for (var i = 0; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; var content = entry.content; var title = entry.title; var url = entry.link; var div = document.createElement('div'); //parentDiv for articles var articleTitle = document.createElement('div'); articleTitle.setAttribute('name', i); //set articleTitle name to article's place in array articleTitle.setAttribute('style', 'font-weight:bold;font-size:15px;'); articleTitle.innerText = title; articleTitle.onclick = function() {populate(content, title, url, i);}; div.appendChild(articleTitle); //adds title to div container.appendChild(div); //adds div to the container } } } function populate(content,title, url, i) { var article = document.getElementByName(i); //gets articleTitle //clickable title var a = document.createElement('a'); //creating title link var href = document.createElement('href'); a.setAttribute('href', url); //putting actual url into html a.setAttribute('style', 'font-size:25px;'); a.innerText = title;//still puts into html //Text var snippet = document.createElement('p'); //creates <p> to throw articles in snippet.innerHTML = content; //renders the article article.appendChild(a); article.appendChild(snippet); } </script> </body> Hello, I am trying to access a dynamic asp variable with onclick either in a javascript function where I can use it globally or set another div id with this dynamic variable. Any help is very much appreciated. Thank you! <script> function doSomething(article_id) } return article_id; } </script> <a href="#test" onClick="doSomething("<%=rsHeadline("article_id")%>")">try here...</a> <div id="test"> <%articleid = request.querystring("article_id") %> <% Response.Write articleid %> The article id is articleid</div> Simply put, I need to take a variable (The number '20' in this case) that is displayed by an input box on my web page and plug it into a function so that whenever I click on a button, the number in the input box will decrease by 1. Seems simple enough, though for hours I've been going at it with no luck. Skipping the rest of my code - I currently have: Code: <head> <title> Online Slots </title> <script type="text/javascript" src="http://dave-reed.com/book/random.js"> </script> <script type="text/javascript"> function DoSpin() { var count; count = 20 document.getElementById("countBox") = count - 1; } </script> </head> <body> <div style="text-align:center"> <input type="button" value="Click to Spin" onclick="DoSpin()" /> <br /><br /> Current Funds: <input type="text" id="countBox" size="4" value="20" onfocus="blur();" /> </div> </body> The entire code is a slot machine project that's supposed to be extremely simple where you hit the button and it spins 3 wheels, 3 of the same image and you win. Every spin takes $1, every win gives $13. The majority of the code is already working, however for some reason I appear to be failing badly at getting the read out to show a decrement of $1 every time you push the button. I know this is a bit newbie of a question to be asking; but I've tried so many different ideas that I've found across w3schools, webdevelopersnotes, dave-reed, ect - and so far I haven't been able to get any of them to work correctly. Any help would be great! Below is the code that is using the name FFF in various places. The effect of all this is that the onclick function is not executed. I would expect a pop up alert when clicking the submit button. This only happens if I rename either the form id or the js variable. Can anyone explain what is going on here ? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Title</title> </head> <script type="text/javascript"> function newobject(){ this.exec=exec; function exec(){ alert("exec"); } } FFF = new newobject(); </script> <body> <form id=" FFF " name="somename" action="" method="GET"> <input type="text" id="someid" name="somename" value="value"> <input onclick=" FFF .exec()" type="submit" id="submitid" name="somesubmit" value="xxx"> </form> </body> </html> Regards Heinz Well, I'm a beginner to coding, so I need some help. I'm trying to create a short, html/javascript mario text game. Now, in the beginning, he fights a goomba. He has a health and energy number as variables: Code: <p><img src="http://img253.imageshack.us/img253/9202/mariodisplayidlefront.png" align="middle" hspace=20> <font size=3 color="red"> Health: <script language= "javascript"> var mariohealth = '20'; document.write(mariohealth); </script> </font> <br><font size=3 color="green"> Energy: <script language= "javascript"> var marioenergy = '20'; document.write(marioenergy); </script> </align> </font> And the goomba has health: Code: <p><br><img src="http://img23.imageshack.us/img23/9438/goombafrontdisplay.png" align="middle" hspace=20> <font size=3 color="red"> Health: <script language= "javascript"> var goombahealth = '10'; document.write(goombahealth); </script> </font> And then, there will be different buttons for different attacks. However, the only one created is "Punch", with this code: <FORM> <INPUT type="button" value="Punch" name="Mario Punch" onClick="?"> </FORM> What would I put in the onClick function to make it subtract 4 health from the goomba and 2 health from Mario I have a html page with a lot of thumbnails. The idea is that when the user clicks on an image the onClick event is to display another detailed form and deliver to that form the name of the image in a variable. In the detailed php-form there is a query to MySQL to retrieve a record. The record will be retrieved by a Query based on the name of the picture. Apparently the PHP cannot do the job. I had an idea to make the thumbnail page as a form and to use use a hidden field with the thummnail name which should be carried on with the $_POST array through the submit button but i do not want to have a submit button. The more elegant way is just by clicking the picture the detailed page is opened and the variable is transferred where my php code can make use of the variable for the query. I have never used java before so you have to excuse for the lack of knowledge. Can anyone gie me an idea how i should implemnt this Best regards MSP I have a html page with a lot of thumbnails. The idea is that when the user clicks on an image the onClick event is to display another detailed form and deliver to that form the name of the image in a variable. In the detailed php-form there is a query to MySQL to retrieve a record. The record will be retrieved by a Query based on the name of the picture. Apparently the PHP cannot do the job. I had an idea to make the thumbnail page as a form and to use use a hidden field with the thummnail name which should be carried on with the $_POST array through the submit button but i do not want to have a submit button. The more elegant way is just by clicking the picture the detailed page is opened and the variable is transferred where my php code can make use of the variable for the query. I have never used java before so you have to excuse for the lack of knowledge. Can anyone gie me an idea how i should implemnt this Best regards MSP Hey all, I'm using a fairly simple accordion script. When I went to take a gander at the page in IE I found that the onclick function of the script doesn't respond. It works in FF, Safari, Chrome and Compatibility Mode in IE 8 the error message IE gives me is Quote: Message: 'h' is null or not an object Line: 13 Char: 77 Code: 0 URI: http://proposalfor.us/js/script.js The problem line (as far as I can tell) is: Code: this.a[s]={}; this.a[s].h=h=T$$(e,v)[0]; this.a[s].c=c=T$$('div',v)[0]; h.onclick=new Function(this.n+'.pr(0,'+s+')'); Any help would be greatly appreciated! Thanks friends! I'm currently working on a project and I am doing a bunch of image switching. I'm having a problem with the following... I have seven medium image objects and one small one. One is at the top and the other 7 are below. When one of the 7 is clicked, it then becomes the one up top and the one up top then takes the place of the image clicked. This needs to be able to happen no matter which of the seven i click. Also when you click one of the seven it runs a script to change 9 other images in the center of the page. this isnt too important because i have it working already. What i have is, each of the seven images run their function that changes the 9 center images and then it runs another function. What i need is for that function to determine which company for example(shaws, lowes, target) the top image belongs to and replace the image that was clicked with the top one. But i also need to replace the NAME="" and ONCLICK="function()" with the proper ones for the original company up top. Please if you can understand what im trying to do let me know, if you need further clarification i can do so. i can draw a picture of what im trying to do or the layout if needed but i cant necessarily show anyone the project due to a non-disclosure. Is it possible disable an onclick after clicking it and then enable it from another onclick by id Code: <img id="one" href="images/homepage/sliders/bonus_button.jpg" style="position:relative; top:30px; left:50px; height:30px; width:70px; float:left;"> This code runs when it is clicked: Code: $("#one").click(function() { runEffectB(); return false; }); What I would like to happen is for either runEffectB() to not run if it was just run or to disable the #one.click once it has run. I am assuming I will be able to re-enable it from another onclick running a similar function. This is jquery and jquery ui if that helps. Any ideas much appreciated. Hi, I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it. I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page. Thanks for all the help P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side... Hello I have a php page in which I declared a js variable... right at the top of the page... <script type="text/javascript"> var tester = 0; </script> Later in the page I test this variable... <script type="text/javascript"> if (tester==1){ do some stuff!! } </script> But I keep getting an error variable _tester undefined Am I missing something obvious... I am new to js... but this seems really straightforward I don't know how I should do ? Quote: <html> <head> <script type="text/javascript"> function add(a,b){ y=a+b return y } var aaa = add(one,two) //one needs to get somehow get the value of yil, in this case 10 var one = function reas(){i=10;if(i<10){yil = 15}; else{yil = 10; yil = one;}; var two = 20; document.write(y) </script> </head> </html> also why doesn't this work? Quote: <html> <head> <script type="text/javascript"> function adder(a,b){ var k=a+b; return k } var hes=adder(5,kol); kol=40; alert(hes); </script> </head> </html> you cannot have variables in callback functions? 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. This might be a stupid question, but is there any memory usage difference between var variable1, variable2; and var variable1; var variable2;? I'm learning how to use faster code hence the question.
Hello I have a piece of javascrip that refreshes the page: ---------- Code: <script type="text/javascript"> <!-- Begin function reFresh() { location.reload(true) } /* Set the number below to the amount of delay, in milliseconds, you want between page reloads: 1 minute = 60000 milliseconds. 2 minutes = 120000 milliseconds 5 minutes = 300000 milliseconds*/ window.setInterval("reFresh()",20000); // End --> </script> -------- I am new to javascript and wanted to use an html options menu in order to be able to choose the refresh interval: Code: <SELECT NAME="refreshtime"> <OPTION VALUE="60000">1 min</option> <OPTION VALUE="120000">2 min</option> <OPTION VALUE="180000">3 min</option> <OPTION VALUE="240000">4 min</option> </SELECT> I know that I have to pass a variable to the function. I have tried several variations but none have worked. I have mostly received a "done with errors" warning. Any help would be appreciated. Thanks Zam If I manually write out "2/22/2012 4:00 PM" in TargetDate, I get the correct result for what I want to do (a countdown). But I want the countdown to always be the current day at 4pm. So I tried the code below thats commented, but it is not working. New to javascript, still reading the books, just hoping for some guidance on this. Code: Next Update: <script language="JavaScript"> var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() TargetDate = "2/22/2012 4:00 PM"; //TargetDate = "document.write(month + "/" + day + "/" + year) + 4:00PM"; BackColor = "white"; ForeColor = "red"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%H%% H, %%M%% M, %%S%% S"; FinishMessage = "Forecasts posted"; </script> <script language="JavaScript" src="countdown.js"></script> |