Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 22-05-2008, 05:57 PM   #1 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,527
Question How to write this in javascript???


I want 2 design a html page which
has following elements:

1> A line of text....e.g Welcome to my site <username>
2> a select box with options as colors (red,blue,green)

whenever the user selects a particular option...the text which has the user name
displayed already,shud change....dynamically to dat color.

Is it possible in javascript....

pls help...
__________________
I'm the One you've been Waiting for...
Zangetsu is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 22-05-2008, 06:16 PM   #2 (permalink)
हॉर्न ओके प्लीज़
 
victor_rambo's Avatar
 
Join Date: Sep 2007
Posts: 1,493
Default Re: How to write this in javascript???

Yes this is possible:
1. Give the username display line an 'id'(eg: <span id="username_display">Welcome Rohan</span>)
2. Set three radio buttons, one each for red, green and blue colors.
3. Whenever a radio button is clicked, use
Code:
document.getElementById("username_display").style["color"]="red";
Thats all,
__________________
विक्टर रॅंबो - चाणकया प्रभावित व्यक्ति

गीक होना माँगता
victor_rambo is offline  
Old 23-05-2008, 10:48 AM   #3 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,527
Default Re: How to write this in javascript???

Quote:
Originally Posted by rohan_shenoy View Post
Yes this is possible:
1. Give the username display line an 'id'(eg: <span id="username_display">Welcome Rohan</span>)
2. Set three radio buttons, one each for red, green and blue colors.
3. Whenever a radio button is clicked, use
Code:
document.getElementById("username_display").style["color"]="red";
Thats all,
cant i use it for dropdown selection box....???
i m new 2 javascript...
pls give me whole codes 2 use...(if there r any )
__________________
I'm the One you've been Waiting for...
Zangetsu is offline  
Old 23-05-2008, 01:06 PM   #4 (permalink)
Perpetual Fresh Stock
 
siddes's Avatar
 
Join Date: Feb 2007
Location: Jaipur
Posts: 50
Default Re: How to write this in javascript???

Your HTML page will be

Code:
<html>
<head>
<script>

</script>

</head>
<body>
<h1 id="welcome">Welcome</h1>

<select id="colorSelect">
<Option value="red">Red</option>
<Option value="blue">Blue</option>
<Option value="green">Green</option>
</select>

<input type="button" value="Change Color" onclick="colorChanger()">

</body>

</html>


Withing the <script> include this

Code:
function colorChanger() {

var welcomeText = document.getElementById("welcome");
var textColor = document.getElementById("colorSelect").value;
welcomeText.style.color=textColor;
}

__________________
http://sid-deswal.110mb.com

No clever lines here, go think them up yourselves.
siddes is offline  
Old 23-05-2008, 04:03 PM   #5 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,527
Default Re: How to write this in javascript???

^Cool...mine is almost same....got dat finally
Code:
<html>
 <head>
 <title>Welcome to this Page User</title>
</head>
 <body>
 <form>
 <p>Welcome to this Page <b id="userName">User</b></p>
<br><br>
 <select id="color" type="select-one" onchange="changeColor()">
 <option value="0">Pink</option>
 <option value="1">Red</option>
 <option value="2">Blue</option>
 <option value="3">Green</option>
 </select>
 </form>
 </body>
 </html>
script (shud be in head)

Code:
 <script type="text/javascript">
 function changeColor()
  {
    if (document.getElementById('color').value==0)
      {
        document.getElementById('userName').style.color ='pink';
      }
     else if (document.getElementById('color').value==1)
      {
        document.getElementById('userName').style.color ='red';
      }else if (document.getElementById('color').value==2)
      {
        document.getElementById('userName').style.color='blue'; 
      }else if (document.getElementById('color').value==3)
      {
      document.getElementById('userName').style.color='green';
      }
  }
  </script>
__________________
I'm the One you've been Waiting for...
Zangetsu is offline  
Old 23-05-2008, 04:16 PM   #6 (permalink)
हॉर्न ओके प्लीज़
 
victor_rambo's Avatar
 
Join Date: Sep 2007
Posts: 1,493
Default Re: How to write this in javascript???

^
shortcut:

Code:
<select>
<option onclick="changeColor('red')">Red</option>
<option onclick="changeColor('green')">Green</option>
<option onclick="changeColor('blue')">blue</option>
</select>
JS:
Code:
function changeColor(color)
{
document.getElementById("userName").style["color"]=color;
}
Another shorter way:

Just put the below snippet. No need to include another function inside script tag
Code:
<select>
<option onclick="document.getElementById('userName').style['color']=this.innerHTML;">Red</option>
<option onclick="document.getElementById('userName').style['color']=this.innerHTML;">Green</option>
<option onclick="document.getElementById('userName').style['color']=this.innerHTML;">Blue</option>
</select>
__________________
विक्टर रॅंबो - चाणकया प्रभावित व्यक्ति

गीक होना माँगता

Last edited by victor_rambo; 23-05-2008 at 04:25 PM. Reason: Automerged Doublepost
victor_rambo is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help with javascript. Kalyan QnA (read only) 1 17-08-2007 07:07 PM
Javascript - Please help me!! prasanna7287 QnA (read only) 3 29-06-2007 06:24 PM
Javascript Help REY619 QnA (read only) 5 21-02-2007 09:31 PM
JavaScript help......... shehan9999 QnA (read only) 4 05-12-2004 06:34 PM
JAVASCRIPT how to ... abixalmon QnA (read only) 1 17-09-2004 12:52 AM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2