JavaScript - A Little Coding Help
Okay, I'm actually just starting out Javascript so I thought you guys could hopefully help me with a bit of a newb question. I'm trying to start a comic website, and in the process of trying to make the "Previous" and "Next" buttons.
Code: <div id="content"> <div id="control"> <div id="prev" style="cursor:pointer" onclick="changeComic()"> <h5>previous</h5> </div> <div id="next" style="cursor:pointer" onclick="comicChange()"> <h5>next</h5> </div> </div> <img id="comic" src="/images/comics/page005.png" alt="there is no alt"> </div> I'm not sure what the Javascript should be really. What I want is, everytime someone clicks the "Previous" button, the src of the img should change from 005 to 004, basically it's just subtracting a "1" from the img src, and the "Next" button does the opposite and adds a "1" to the img src. Similar TutorialsI had it working at school but im messing something up here, pretty much whats supposed to happen is I have a page full ofpictures, and when I hover over 1 all of them are supposed to go transparent except for the image highlighted, can anyone point out whats wrong? Also im using mozilla, i dont understand whats wrong, its something with the for statement because the function itself is working as it should. Code: function into(whoseCalling) { document.getElementById(whoseCalling).style.borderStyle = "double"; document.getElementById(whoseCalling).style.borderTopColor = "blue"; document.getElementById(whoseCalling).style.borderBottomColor = "red"; document.getElementById(whoseCalling).style.borderLeftColor = "yellow"; document.getElementById(whoseCalling).style.borderRightColor = "green"; document.getElementById(whoseCalling).style.borderWidth = "8px"; for (i=0; i<30; i++) { document.getElementById("img" +i).style.opacity = ".5"; } } The code below is part of a working program which inserts "tentpay" and date paid. I'm trying to add the code which is below the comment line(//*). It does nothing? can someone look at it? Code: function calculate_paid(v) { var rentdue = document.getElementById("rentdue"); var prevbal = document.getElementById("prevbal"); var misc = document.getElementById("misc"); var late = document.getElementById("late"); var amtpaid = document.getElementById("amtpaid"); var tentpay = document.getElementById("tentpay"); var hudpay = document.getElementById("hudpay"); var datepaid = document.getElementById("datepaid"); var late = document.getElementById("late"); var dateNow = new Date(); var dayNow = dateNow.getDate(); var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear(); switch(v) { case amtpaid: var tpay = amtpaid.value - hudpay.value; if(tpay >= 0){tentpay.value = tpay;} if(amtpaid.value > 0){datepaid.value = datePaid;} break; case tentpay: if(!hudpay.value || hudpay.value == " "){hudpay.value = 0;} if(!tentpay.value || tentpay.value == " "){tentpay.value = 0;tentpay.select();} amtpaid.value = parseInt(tentpay.value) + parseInt(hudpay.value); if(tentpay.value > 0){datepaid.value = datePaid;} break; case hudpay: if(!tentpay.value || tentpay.value == " "){tentpay.value = 0;} if(!hudpay.value || hudpay.value == " "){hudpay.value = 0;hudpay.select();} amtpaid.value = parseInt(tentpay.value) + parseInt(hudpay.value); if(hudpay.value > 0){datepaid.value = datePaid;} break; //* case prevbal: var balance = parseInt(rentdue.value) + parseInt(prevbal.value) + parseInt(misc.value) - parseInt(hudpay.value); if(amtpaid.value < balance.value){ prevbal.value = parseInt(balance.value) - parseInt(amtpaid.value);} if(dayNow.value > 5){late.value = "L"; prevbal.value = prevbal.value + 10;} break; } } hi all, i have tried some coding. it only works partly. the alert message box doesn't display. i am not sure of the error. pls help. <html> <head> <title> my firs web page </title> <script language="javascript"> function abc(){ alert("welcome"); } </script> </head> <body> <script language="javascript"> document.write("<h1 align=center> hesitation kills</h1>"); </script> <form name="form1"> enter your name:<input type="text" name="val"> <input type="button" name="submit" value="display" onlick="abc()"> <input type="button" name="color" value=" GREEN " onclick="document.bgColor='green'"> </form> </body> </html> thanks, breentha Hey, I am new to coding. I'm learning Java, but I'm wondering if that's the first language I should learn, or should I study something else first. Any help would be very appreciated. I would like to learn how to make software programs, design websites, and hopefully develop video games.
I found this code online to create a like/send buttons for Facebook to put under my posts on my website. When the user clicks "Like" or "Send" I want the content tags from the website to be automatically input into the user's Facebook post: so the Facebook plug-in/post function will attach the picture and link to the site, and have the tags (already associated with the picture within my site's coding) automatically entered as text into the post. I'm not a programmer and thought this might be a good place to get some help. Does something like this already exist that can be altered/edited? I am not familiar with this, and I'm having difficulty trying to explain it. Here is the code I have so far. <!-- Facebook Like+Send script Start --> <b:if cond="data:post.isFirstPost"> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "http://connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> </b:if> <!-- Facebook Like+Send script End --> <!-- Facebook Like+Send button Start --> <div style='float:left;padding:5px 5px 5px 0;'> <fb:like expr:href='data:post.url' font='' layout='standard' send='true' show_faces='false' width='450' colorscheme='light'></fb:like> </div> <!-- Facebook Like+Send button End --> Right I have written some code very similar to this, and then found the similar code somewhere else, and what I want to do, is to be able to call a couple of different scripts into the one script, I have been at this since 9am uk time and I am bashing my head against a brick wall. Code: <script type="text/javascript"> function Msg1(){ document.getElementById('myText').innerHTML = '<script src="page1.js" type="text/javascript"></script>'; } function Msg2(){ document.getElementById('myText').innerHTML = '<script src="page2.js" type="text/javascript"></script>'; } </script> <input type="button" onclick="Msg1()" value="Show Message 1" /> <input type="button" onclick="Msg2()" value="Show Message 2" /> <p id="myText"></p> As a personal note, I have asperger (a form of Autism) and ADHD, and I cant sleep until I can either get this to work, or someone who has more of an idea what I am trying to do tells me your not going to get it work, any help will be appreciated A short summary of what I'm trying to do is this: I manually charge credit cards for my bosses online business. Doing this requires me to manually enter information in from his websites back office in to a different browser, using "Navigate, Merchant Plus" (that's a site used for banking etc. and allows you to charge cards through it). I'll be the first to admit I know nothing about coding, and I was just doodling with it trying to see if there's a way to automate this. If I can get the code, I can give it to my boss and he can enter it into the website and have a button you can press to transfer the information out of the fields required to charge the card on to the navigate websites fields where you place the information. A sample of the code off of his website - one of the fields that needs to be transferred is this: <td class="main"><input name="update_info_cc_expires" size="4" value="0412" onChange="updateOrdersField('cc_expires', encodeURIComponent(this.value))"></td> The field it would need to go in to on the navigate is this: <tr> <td align="right" valign="top" width="43%">CVV Code:</td> <td align="left" valign="top"><input type="text" id="x_Card_Code" name="x_Card_Code" size="8" maxlength="6" /></td> </tr> ___________________________________________ So I'm unsure if this is the code needed to do what I'm talking about doing, but hopefully I've grabbed enough of the code for some pro to work with. If someone can tell me how to transfer just that one field in to the other, then I could apply it to the rest of the fields and save my boss the time on doing it, and make it a lot easier and less time consuming for me at work while I'm at it. Thanks and get back to me soon! I really appreciate anyone that takes the time to try to help. Let me know if I need to grab more code than what I did. In my javascript code I have to type in a number in a textbox then click a button. When the button is pressed a popup message will come up displaying the number I typed in the text box. I have no clue how to do it, could someone give me an example? Thanks. P.S. I can't use a prompt. if i wanted to create a code that takes the value of a textbox, multipliy it by itself what would i try to do?
ok im new to coding and was woundering is there a way to open up a game through a program that could have an attached macro or anything.. like for example i would have a racing game that u need to shift and i open it with the coded program and it shifts like an automatic. i sorry if its in the wrong section . thanks I need a script able to find and store a piece of text from my webpages and place it between the code of my links. The piece of text is the user name and is inside a DIV Element. I'll include an example of both the DIV Element and the link to see who can give me some help coding this or at least tell me the tags I should use. The DIV element looks like this: <div>Hi User Name,</div> The link looks like this: <a href="http://www.xxxxxxx.com/click-xxxxxxx-xxxxxxxx">Link</a> I need the following as a result using Javascript: <a href="http://www.xxxxxxx.com/click-xxxxxxx-xxxxxxxx?sid=User+Name">Link</a> Hi, As part of a package deal I received a javascript script for redirecting a webpage. Now I already have simple redirection but wanted to see how this one did the redirection. But it starts off by defining an array with strange sets of characters. Is this hexadecimal or something ? Can I convert it into a more readable and understandable form ? var _0x46d5=["\x67\x65\x74\x54\x69\x6D\x65","\x73\x65\x74\x54\x69\x6D\x65","\x3B\x20\x65\x78\x70\x69\x72\x65\x73\ x3D","\x74\x6F\x47\x4D\x54\x53\x74\x72\x69\x6E\x67","","\x63\x6F\x6F\x6B\x69\x65","\x3D","\x3B\x20\x 70\x61\x74\x68\x3D\x2F","\x3B","\x73\x70\x6C\x69\x74","\x6C\x65\x6E\x67\x74\x68","\x73\x75\x62\x73\x 74\x72\x69\x6E\x67","\x63\x68\x61\x72\x41\x74","\x20","\x69\x6E\x64\x65\x78\x4F\x66","\x26","\x3F"," \x68\x72\x65\x66","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x73\x6C\x69\x63\x65","\x70\x75\x73\x68","\x65 \x7A\x6D\x62\x72\x65\x64","\x4E","\x59","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x76\x65\x6E\x64\x6F \x72","\x6F\x70\x65\x72\x61","\x74\x65\x73\x74","\x73\x75\x62\x73\x74\x72"]; function createCookie(_0x810ex2,_0x810ex3,_0x810ex4,_0x810ex5){ ... the script continues using the array elements above. Thanks for any insights. . Hello everybody, I have a nice search engine but its seems i can't put it twice on the same page: Code: <script language="JavaScript"> function startSearch(){ searchString = document.searchForm.searchText.value; if(searchString != ""){ searchEngine = document.searchForm.whichEngine.selectedIndex + 1; finalSearchString = ""; if(searchEngine == 1){ finalSearchString = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=" + searchString; } if(searchEngine == 2){ finalSearchString = "http://av.yahoo.com/bin/query?p=" + searchString + "&hc=0&hs=0"; } if(searchEngine == 3){ finalSearchString = "http://www.excite.com/search.gw?trace=a&search=" + searchString; } if(searchEngine == 4){ finalSearchString = "http://www.hotbot.com/?SW=web&SM=MC&MT=" + searchString + "&DC=10&DE=2&RG=NA&_v=2&act.search.x=89&act.search.y=7"; } if(searchEngine == 5){ finalSearchString = "http://www.infoseek.com/Titles?qt=" + searchString + "&col=WW&sv=IS&lk=noframes&nh=10"; } if(searchEngine == 6){ finalSearchString = "http://www.lycos.com/cgi-bin/pursuit?adv=%26adv%3B&cat=lycos&matchmode=and&query=" + searchString + "&x=45&y=11"; } if(searchEngine == 7){ finalSearchString = "http://netfind.aol.com/search.gw?search=" + searchString + "&c=web&lk=excite_netfind_us&src=1"; } location.href = finalSearchString; } } // --> </script> <basefont face="Verdana, Arial, sans-serif"> <form name="searchForm"> <table width=320 border cellpadding=3 cellspacing=2 bgcolor=444444> <tr> <td bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search for:<br> <td bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search from: <td bgcolor=lightblue> <tr> <td bgcolor=navajowhite><input style="background: dddddd" name="searchText" type="text"> <td bgcolor=navajowhite> <select style="background: dddddd" name="whichEngine"> <option selected>Altavista <option>Yahoo! <option>Excite <option>Hotbot <option>Infoseek <option>Lycos <option>AOL Netfind </select> <td bgcolor=navajowhite><input type="button" value="Send" onClick="startSearch()"> </select> </table> </form> Can someone tell me how to put the code twice in the html page without creating a conflict as a result of identical codes? I am trying to build a simple test/questionnaire where the user inputs answers into a form. These answered are then checked with stored data in arrarys to see if they are correct or not. At the end the score is totaled and given to the user PROBLEM im confused at to how to structure the code and also am aware that i am missing several coding functions ect e.g. i know that i need to use 'getelementbyid' somewhere. ANY HELP WOULD BE APPRECIATED, THANK YOU CODE Code: <html> <script language="text/JavaScript"> function checkanswer() { if (q1==answer[0]) { alert('Right well done u got it correct') } else { alert ('unlucky you got it wrong') } answer = new Arrary(); answer[0] = "blue"; answer[1] = "green"; answer[2] = "red"; </script> <body> <form action="qform"> question 1: <input type="text" id="q1" value="" /> <br /> question 2: <input type="text" id="q2" value="" /> <br /> question 3: <input type="text" id="q3" value="" /> <br /> <input type="submit" value="submit" /> </form> </body> </html> Hi My code is very very long. Is this ok? Is there anyway I can make it better without loosing out browsers being able to read the contents? http://www.photoshopcourselondon.com/home.html Any suggestions welcome Thanks Mikael Hey im having a problem putting a swf video in a website Code: <script type="text/javascript" src="swfobject.js"></script> <script type="text/javascript"> function showIt(){ var so = new SWFObject('./images/portfolio/tours/stoodly_pano/panoStudioViewer.swf',Stoodly','325','325','9'); so.addParam('allowscriptaccess','always'); so.addParam('bgcolor','#FFFFFF'); so.addParam('flashvars','file=stoodly2.xml&autostart=true'); so.write('portfolio-content'); } </script> With this code it shows a loading bar thats as far as it goes can anyone show me where i am going wrong I am wanting a script to find and replace numbers in text it is not working for me so will someone help? I believe that this will work. Code: findAndReplace('(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98)', '(d)'); However, I need the variable a to equal whatever number it finds. (e.g. 27 --> a=27) I have no idea on how to do that These are theformulas that i need it to do Code: var a = _____ var b = 100 - a var c = 17932 % b var d = a + c Im creating an applet that adds two digits. Pretty simple, I have the layout as it needs to be, but I guess I dont know where to put the method or what the actual method is so that it adds the two digits and then puts them in the results textfield. Code: /* document segment filename: ActionApplet author: sullivan date: october.2010 */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class addNumbers extends JApplet implements ActionListener { /* ----------------------------- declarations */ // color objects Color white = new Color(255, 255, 255); Color black = new Color(0, 0, 0); // components JLabel inputLabelJLabel; JTextField inputLabelJTextField; JLabel outputLabelJLabel; JTextField outputLabelJTextField; JLabel finalLabelJLabel; JTextField finalLabelTextField; JButton enterJButton; JButton clearJButton; // variables String inputName; String outputName; public void init() { setLayout(null); setSize(400, 400); /* ------------------- initialization */ inputLabelJLabel = new JLabel(); inputLabelJLabel.setBounds(100, 50, 150, 20); inputLabelJLabel.setFont(new Font("Default", Font.PLAIN, 12)); inputLabelJLabel.setText("Enter First Integer"); inputLabelJLabel.setForeground(black); inputLabelJLabel.setHorizontalAlignment(JLabel.LEFT); add(inputLabelJLabel); inputLabelJTextField = new JTextField(); inputLabelJTextField.setBounds(230, 50, 150, 20); inputLabelJTextField.setFont(new Font("Default", Font.PLAIN, 12)); inputLabelJTextField.setHorizontalAlignment(JTextField.CENTER); inputLabelJTextField.setForeground(black); inputLabelJTextField.setBackground(white); inputLabelJTextField.setEditable(true); add(inputLabelJTextField); outputLabelJLabel = new JLabel(); outputLabelJLabel.setBounds(100, 80, 150, 20); outputLabelJLabel.setFont(new Font("Default", Font.PLAIN, 12)); outputLabelJLabel.setText("Enter Second Interger"); outputLabelJLabel.setForeground(black); outputLabelJLabel.setHorizontalAlignment(JLabel.LEFT); add(outputLabelJLabel); outputLabelJTextField = new JTextField(); outputLabelJTextField.setBounds(230, 80, 150, 20); outputLabelJTextField.setFont(new Font("Default", Font.PLAIN, 12)); outputLabelJTextField.setHorizontalAlignment(JTextField.CENTER); outputLabelJTextField.setForeground(black); outputLabelJTextField.setBackground(white); outputLabelJTextField.setEditable(true); add(outputLabelJTextField); finalLabelJLabel = new JLabel(); finalLabelJLabel.setBounds(100, 110, 150, 20); finalLabelJLabel.setFont(new Font("Default", Font.PLAIN, 12)); finalLabelJLabel.setText("Addition Results"); finalLabelJLabel.setForeground(black); finalLabelJLabel.setHorizontalAlignment(JLabel.LEFT); add(finalLabelJLabel); finalLabelTextField = new JTextField(); finalLabelTextField.setBounds(230, 110, 150, 20); finalLabelTextField.setFont(new Font("Default", Font.PLAIN, 12)); finalLabelTextField.setHorizontalAlignment(JTextField.CENTER); finalLabelTextField.setForeground(black); finalLabelTextField.setBackground(white); finalLabelTextField.setEditable(false); add(finalLabelTextField); enterJButton = new JButton(); enterJButton.setBounds(100, 300, 100, 20); enterJButton.setFont(new Font("Default", Font.PLAIN, 12)); enterJButton.setText("Enter"); enterJButton.setForeground(black); enterJButton.setBackground(white); add(enterJButton); enterJButton.addActionListener(this); clearJButton = new JButton(); clearJButton.setBounds(210, 300, 100, 20); clearJButton.setFont(new Font("Default", Font.PLAIN, 12)); clearJButton.setText("Clear"); clearJButton.setForeground(black); clearJButton.setBackground(white); add(clearJButton); clearJButton.addActionListener(this); } public void actionPerformed(ActionEvent event) { Object obj = event.getSource(); /* the following lines of code are commented out, remove the // to un-comment after the components are initialized */ if(obj == enterJButton) { getFirstMethod(); } else if(obj == clearJButton) { clearAll(); } } public void getFirstMethod() { inputName = Double.parseDouble(inputLabelJTextField.getText()); outputName = Double.parseDouble(outputLabelJTextField.getText()); if (e.getSource() == addButton) { answer.setText(String.valueOf(x + y)); symbol.setText(enterJButton); } { public void getOutput() { outputLabelJTextField.setText("" + inputName); } public void clearAll() { inputLabelJTextField.setText(""); inputLabelJTextField.requestFocusInWindow(); outputLabelJTextField.setText(""); } } Hello, This is my second post on the forum and I am a coding beginner and therefore relatively new to the forum so sorry for any naive ignorance in the questions I may ask. I was wondering if anyone could please pass their assisstance regarding a functioning question...? I am completely stuck and cannot get my head around it on which methods are necessary?! For this question I think I have to follow the specification pretty regimently, eg. the example result has to include the double quotes around 'prog found in pages 0,3,5,6,9'. v) function findIdxsC(s) - to return a string containing the indexes in the pages array where s was found in the content part, e.g. "prog found in pages 0,3,5,6,9" [Note that this function will not contain an alert] Example call: findIdxsC("prog") Example result: "prog found in pages 0,3,5,6,9" Cheers, George |