Jump to content

demuro1

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by demuro1

  1. You are so awesome. Thanks. This is perfect!!!!!! I'll be able to assimilate this code into mine now very well. edit:ok I have questions about how this works: how do the buttons work without an onclick event.-i see that the function begins running with the page load so does that means that the function is always waiting for an on on click-does the function react to all button clicks, but only takes action for objects named button?-how do i return a click with the page load?-is it possible to pass this.indexNumber out of the function? and this last question isn't something I need answered but I am curious about how you would make this work with the onclick in the input tag thanks again
  2. Hello again everyone. Again thanks in advance for your help. I am in a web app class and we have a semester long project that is updated every week. I am using the below code. when I click any button the alert displays the correct button value. The second alert needs to return the element index of the array. so if button 0 is clicked the second alert needs to display 0if button 1 is clicked the second alert needs to display 1if button 2 is clicked the second alert needs to display 2if button 3 is clicked the second alert needs to display 3 I need the function to determine the position in the array of document.getElementsByName('button') connected to the button clicked does anyone know how to do this, is it possible, can you suggest something that return a value based on the name property? thanks so much for your help <html> <head> <title>test</title> <style> /*sadly this is done without style*/ </style> <script type='text/javascript'> function indexNum(x) { var y = document.getElementsByName('button') alert(x.value); alert(x.name.indexOf('button')); } </script></head> <body> <input type="button" name='button' value='button 0' onclick="indexNum(this)"><br> <input type="button" name='button' value='button 1' onclick="indexNum(this)"><br> <input type="button" name='button' value='button 2' onclick="indexNum(this)"><br> <input type="button" name='button' value='button 3' onclick="indexNum(this)"> </body> </html> I did find this and it works but I can't seem to get it to work with button. Any idea on how to change the onclick and p tags to a button <html xmlns="http://www.w3.org/1999/xhtml"><head><title></title> <script type="text/javascript"> function countP() {var pElemA = document.getElementsByTagName('p'); for(var i=0; i < pElemA.length; i=i+1) {pElemA[i].indexNum = i; //store the index in your own property //assign an onclick function for the ppElemA[i].onclick = function() {alert(this.indexNum);}}} </script> </head><body onload="countP();"> <p>Click to get my index.</p> <div>div element</div> <p>Click me too...</p> <p>And me.</p> </body></html>
  3. with no e that would be just as badoh man it makes for a funny story in class but the frustration would be unbearable
  4. damn it how did I miss that. I know you need to declare it as a function. Damn sorry, thanks! at least I'm not as bad as one guy in my class. his script rage looked like this <script type='text/javascrip'> he forgot the t in javascript, he recoded his assignment 4 times before he caught the mistake Thanks so much again!!!!
  5. Basically I want to click on an image and have an onclick call a javascript function. It does not work. I have successfully done this with an alert but if I move the alert to a function it stops working. thanks for any help you can provide these first two pieces are what I am trying to do. <script type='text/javascript'> payNow() { alert('PayPal Button Pushed'); } </script> <img src="images/navigationImages/paypal.gif" onclick="payNow()"> this works <img src="images/navigationImages/paypal.gif" onclick="alert('PayPal Button Pushed')">
  6. dsonesuk that worked. I had to add e.charCode though. I can only guess what the code means but I really appreciate your help
  7. hello all. I am making a catalog page for a class I am in. I'm still fairly new to javascript but I am having an issue with an onkeypress. It works in safari and IE but not in firefox. Does anyone have any suggestions? I'd appreciate any help you can provide. Thanks function keystrokeSubmit(text){ var prskeyrtrn = event.keyCode || event.which; if (prskeyrtrn == 13 && text.id == 'searchField') { search(); document.getElementById('searchField').value = 'search'; } else if (prskeyrtrn == 13 && text.id == 'pageNumber') { pageNumber('Current Page'); } else{}} <table align="right"> <tr><td><u>You Are on page:</u></td></tr> <tr><td><input type="text" id="pageNumber" value="0" onkeypress=keystrokeSubmit(this)></td></tr> </table>
  8. oh man that works way better!!! Thanks again
  9. I want to thank you guys so much for your help. I have gotten this question solved 3 ways which is awesome. One uses only the getElementsByTagName method one uses both getElementsByTagName and getElementById methods and the last, and by far the most elegant uses only getElementById. here's what I ended up with. Thanks again so much for all your help! var myTable = document.getElementById("myTable");var myCol = myTable.rows[0].cells.length; var rowIndex = 0; // rowindex, in this case the first row of your tablevar table = document.getElementById('myTable'); // table to perform search onvar row = table.getElementsByTagName('tr')[rowIndex];var cells = row.getElementsByTagName('td');var cellCount = cells.length; var rowIndex = 0; // rowindex, in this case the first row of your tablevar tables[0] = document.getElementsByTagName("table");var myTable = tables[0]; // 0 is the first table of the listvar row = myTable.getElementsByTagName('tr')[rowIndex];var cells = row.getElementsByTagName('td');var cellCount = cells.length;
  10. An excellent question! Right now in my class we are working with the method getElementsByTagName() and the question I posted at the top of the page is in the homework under the getElementsByTagName() section. That and I think it would be awesome to make work, I have found the course I'm taking to be very easy but also very enjoyable and this is literally the first thing I have not been able to get to work on my own in the 5 weeks the class has been going on. So I'm kind of on a mission to make this thing work if it's at all possible.
  11. yes I did. did you read this whole thread? Ingolme referenced getElementsByTagName earlier ah, you're right. it's getElementsByTagName.my mistake, I forgot the s. here's a link:http://www.w3schools...tsbytagname.asp I understand that. If you look at the posted code for table I set the id = 'myTable" and then I call that in getElementById. I can understand the confusion as I posted the wrong code above. I am trying to store a table in the variable myTable and then I am trying to extract certain information out of it. As I said I can make my code work with a getElementById. I still have the same question about making the page work with a getElementsByTagName. I see I posted the incorrect code above. I will add the code that does work here but if anyone has any suggestions on how to make this work with a getElementsByTagName I'd really appreciate it. I appreciate the feedback and all the help. Thanks for taking time to reply! Also thescientist…you seem a little hostile. It's probably just the way I'm reading everything, like when a text message doesn't carry the right tonal inflection and so it doesn't carry the total meaning of what you're trying to say so I'm sure it's just me Thanks again for all the help! <html><head> <script> function displayResult() { var myTable = document.getElementById("myTable"); var myCol = myTable.rows[0].cells.length; alert(myCol); }</script></head><body><table id="myTable" border="1"> <tr> <td>cell 1,1</td> <td>cell 1,2</td> <td>cell 1,3</td> <td>cell 1,4</td> </tr> <tr> <td>cell 2,1</td> <td>cell 2,2</td> <td>cell 2,3</td> <td>cell 2,4</td> </tr> <tr> <td>cell 3,1</td> <td>cell 3,2</td> <td>cell 3,3</td> <td>cell 3,4</td> </tr></table><br><input type="button" value="return columns" onclick=displayResult()></body></html>
  12. Wow! Thank you so much for your help. I got it to work. I was wondering if there was a way to get this to work with a getElementByTagName. I must be structuring the javascript wrong based on how getElementById and getElementByTagName work. can you offer any suggestions. You've been such a great help. Thanks again. <html><head><script> function displayResult() { var myTable = document.getElementByTagName("myTable"); var myCol = myTable.rows[0].cells.length; alert(myCol); }</script></head><body><table id="myTable" border="1"> <tr> <td>cell 1,1</td> <td>cell 1,2</td> <td>cell 1,3</td> <td>cell 1,4</td> </tr> <tr> <td>cell 2,1</td> <td>cell 2,2</td> <td>cell 2,3</td> <td>cell 2,4</td> </tr> <tr> <td>cell 3,1</td> <td>cell 3,2</td> <td>cell 3,3</td> <td>cell 3,4</td> </tr></table><br><input type="button" value="return columns" onclick=displayResult()></body></html>
  13. It's the only table on the web page. it's not the rows I need, that part I can do and your code was very helpful. I need the number of columns per row
  14. Ingolme, I appreciate the help so far. Here is what I am working on. I'm still trying to return the number of columns I tried your suggestion but it returns [object HTMLTableElement]. In my code I commented out what I was trying. My solution did not work unfortunately. I appreciate all your help. <html><head><script> function displayResult() { /* var myRows = document.getElementByTagName("tr"); var myCol = myRows[0]; alert(myCol.length);*/ var x = document.getElementsByTagName("table"); var firstTable = x[0]; alert(firstTable); } </script></head> <body><table id="myTable" border="1"> <tr> <td>cell 1,1</td> <td>cell 1,2</td> <td>cell 1,3</td> <td>cell 1,4</td> </tr> <tr> <td>cell 2,1</td> <td>cell 2,2</td> <td>cell 2,3</td> <td>cell 2,4</td> </tr> <tr> <td>cell 3,1</td> <td>cell 3,2</td> <td>cell 3,3</td> <td>cell 3,4</td> </tr></table><br /><input type="button" value="return columns" onclick=displayResult()></body></html>
  15. I'm taking a class in javascript and I have a question I need a little help with. I think I have a basic understanding of what's needs to happen but I'm not sure about the syntax. Here's the question: Suppose I have a JavaScript variable named myTable. Suppose myTable stores an HTML table. Write a snippet of JavaScript code to retrieve the number of columns in the table. Store the number of columns in a variable named numberOfColumns. HINT: Find the number of cells that are in the first row I think what I need is something like this: var numberOfColumns = document.getElementByTag("table") or something with a row.length but I'm a little lost. I'd appreciate any help the forum can provide. Thanks
×
×
  • Create New...