please help onClick js code

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2009
Posts: 15
Reputation: dmmajorstudent is an unknown quantity at this point 
Solved Threads: 0
dmmajorstudent dmmajorstudent is offline Offline
Newbie Poster

please help onClick js code

 
0
  #1
Nov 4th, 2009
hello, i'm a student trying create a website using javascript. i am not familiar with javascript and i must use it to change only the content on my page. i have been stuck on this for days and i just cannot get it right.

using the 960 grid on the website what is the code to remove the behavior of my sidebar links?

also how do i add an onClick feature to my sidebar links?

the last question i have is. what is the correct code to change only the content of the page while everything else remains the same??

This is my html for the side bar and content div.


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!--HOT RODS LINKS -->
  2.  
  3. <div class="grid_3" id="car_links">
  4. <script type="text/javascript" src="js/hotrods.js">
  5. <ul>
  6. <li ><a href="#">Famous Hot Rods</a></li>
  7. <li><a href="#">Electric Cars</a></li>
  8. <li ><a href="#">Pre World War II</a></li>
  9. </script>
  10.  
  11. </ul>
  12. </div>
  13. <!--CONTENT -->
  14.  
  15.  
  16. <div class="grid_8" id="content">
  17.  
  18. <p>Click On list for Hot Rod List for details. </p>
  19. <p id="text1">
  20. </p>
  21.  
  22.  
  23.  
  24.  
  25. </div>
  26.  
  27. <div class="clear"></div>
Last edited by Ezzaral; Nov 4th, 2009 at 12:27 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 318
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 51
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz
 
0
  #2
Nov 4th, 2009
Originally Posted by dmmajorstudent View Post
hello, i'm a student trying create a website using javascript. i am not familiar with javascript and i must use it to change only the content on my page. i have been stuck on this for days and i just cannot get it right.
a good place to learn javascript is w3schools
Originally Posted by dmmajorstudent View Post
using the 960 grid on the website what is the code to remove the behavior of my sidebar links?
I have no idea what this means
Originally Posted by dmmajorstudent View Post
also how do i add an onClick feature to my sidebar links?
you add an onclick event like this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a onlick="somejsfunction()">click here</a>
Originally Posted by dmmajorstudent View Post
the last question i have is. what is the correct code to change only the content of the page while everything else remains the same??
for this you will use ajax, which you can also learn at w3schools here
Life... Is a Moment
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 15
Reputation: dmmajorstudent is an unknown quantity at this point 
Solved Threads: 0
dmmajorstudent dmmajorstudent is offline Offline
Newbie Poster
 
0
  #3
Nov 4th, 2009
Originally Posted by Thirusha View Post
a good place to learn javascript is w3schools

I have no idea what this means

you add an onclick event like this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a onlick="somejsfunction()">click here</a>

for this you will use ajax, which you can also learn at w3schools here



I've tried using w3 schools. been doing it for the last couple days and every time i go back and reedit the coding i cannot get it to work. its very frustrating. i've been trying to use documentwrite and getElementById.
what is the code to change content within my content div?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 17
Reputation: futingkiller is an unknown quantity at this point 
Solved Threads: 2
futingkiller futingkiller is offline Offline
Newbie Poster
 
0
  #4
Nov 4th, 2009
if you want to change only a part of the text from inside of your website try something like this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function change_content()
  2. {
  3. document.getElementById('content').innerHTML='the new text';
  4. }



and you call this function on a onclick envent... something like:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <div id='content' onclick='change_content()'>click here</div>
i didn't understand exactly what you want... this is what i understood
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 15
Reputation: dmmajorstudent is an unknown quantity at this point 
Solved Threads: 0
dmmajorstudent dmmajorstudent is offline Offline
Newbie Poster
 
0
  #5
Nov 4th, 2009
ah sorry i wasn't clear. using an onClick code. i wanted to know what the javascript code is so that any time i click on the links below only the content in the . w3 schools isn't helping me that much and neither is the book i have. i have never used javascript before.

<div class="grid_8" id="content"> would change.


so within these links. i would have paragraphs of different information in each link. the famous hot rods links would have its own information and electric cars...
  1. <li ><a href="#">Famous Hot Rods</a></li>
  2. <li><a href="#">Electric Cars</a></li>
  3. <li ><a href="#">Pre World War II</a></li>
  4. </script>
Last edited by peter_budo; Nov 5th, 2009 at 7:07 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 17
Reputation: futingkiller is an unknown quantity at this point 
Solved Threads: 2
futingkiller futingkiller is offline Offline
Newbie Poster
 
0
  #6
Nov 4th, 2009
Originally Posted by dmmajorstudent View Post
ah sorry i wasn't clear. using an onClick code. i wanted to know what the javascript code is so that any time i click on the links below only the content in the . w3 schools isn't helping me that much and neither is the book i have. i have never used javascript before.

<div class="grid_8" id="content"> would change.


so within these links. i would have paragraphs of different information in each link. the famous hot rods links would have its own information and electric cars...
<li ><a href="#">Famous Hot Rods</a></li>
#
<li><a href="#">Electric Cars</a></li>
#
<li ><a href="#">Pre World War II</a></li>
#
</script>
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <li ><a href="javascript:change_content('Famous Hot ROds');">Famous Hot Rods</a></li>
  2.  
  3. <li><a href="javascript:change_content('electric cars');">Electric Cars</a></li>
  4.  
  5. <li ><a href="javascript:change_content('pre ww2');">Pre World War II</a></li>
and the function is:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function change_content(a)
  2. {
  3. document.getElementById('content').innerHTML=a;
  4. }
this script changes the content in the div that has the ID "content" into what he receives in the function: change_content('pre ww2'); when you click the links
if you want to write something diferent, change the
document.getElementById('content').innerHTML=a; into something diferent.
hope you understood
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 15
Reputation: dmmajorstudent is an unknown quantity at this point 
Solved Threads: 0
dmmajorstudent dmmajorstudent is offline Offline
Newbie Poster
 
0
  #7
Nov 4th, 2009
thanks alot. this is starting to help me. now without using inner html. how do i add in specific paragraphs of information to these assigned links. like lets take famous cars for example.. and i write all this information about it. in javascript without using innerhtml how do i change the content and place it into the content div every time i click on one of those links?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 17
Reputation: futingkiller is an unknown quantity at this point 
Solved Threads: 2
futingkiller futingkiller is offline Offline
Newbie Poster
 
0
  #8
Nov 4th, 2009
Originally Posted by dmmajorstudent View Post
thanks alot. this is starting to help me. now without using inner html. how do i add in specific paragraphs of information to these assigned links. like lets take famous cars for example.. and i write all this information about it. in javascript without using innerhtml how do i change the content and place it into the content div every time i click on one of those links?
there is nothing wrong with using innerHTML (btw it's case sensitive).
you can make a function that receives the #number of the link he clicked and check which one was clicked and put the text in the div according to the link that was clicked...
from what i know that is the only way to change what the div contains.... you can put any HTML code inside that div, and the browser will interpret it. for example:
document.getElementById('content').innerHTML="<table><tr><td> first tab </td></tr></table>"
if you are happy with my help mark this treath as solved
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC