Solved

js html hookup...

Posted on 2012-04-09
4
241 Views
Last Modified: 2012-04-10
I have:

<html>
  <head>
        <title>Polulate List Box</title>
  </head>

  <body>
      <h1>Polulate List Box</h1>
      
            <select name="drop1" id="Select1" size="6" multiple="multiple">
            <option value="1">Group 1</option>
            <option value="2">Group 2</option>
            <option value="3">Group 3</option>
            <option value="4">Group 4</option>

</select>

  </body>
</html>

Question 1: How can I hook this code to groupData.js file below to dynamically to pull the data from js file.

var groupNames = ["Group 1", "Group 2", "Group 3", "Group 4", "Group 5"];

var select = $("<select/>");
$(groupNames).each(function() {
    select.append($("<option/>").text(this.toString()));
});

$("h1").after(select);

Question 2: How can I add event handler so upon click on an item (Group 2), something like

You clicked on Group 2

to popup.

Thank you.
0
Comment
Question by:Mike Eghtebas
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 37824314
Q1: put it in a js file and a method

function populateBox()
{
  var groupNames = ["Group 1", "Group 2", "Group 3", "Group 4", "Group 5"];

var select = $("<select/>");
$(groupNames).each(function() {
    select.append($("<option/>").text(this.toString()));
});

$("h1").after(select);
}

and then call this method at the ready event of document

$(document).ready(function(){
populateBox();
});

Q2: call this method after calling populateBox() in the same document ready event handler


$(document).ready(function(){
populateBox();
 $("select").onchange(function(){
    //this method will be called when any option is selected
 });
});

check this link
http://jetlogs.org/2007/09/03/jquery-select-boxes-and-change-events/
http://stackoverflow.com/questions/1280499/jquery-set-select-index/1280518#1280518
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 37824838
obviousely, I need to do some reading. But for now, could you possibly revise the html below to do the job?

<html>
  <head>
        <title>Polulate List Box</title>
  </head>

  <body>
      <h1>Polulate List Box</h1>
       
            <select name="drop1" id="Select1" size="6" multiple="multiple">
            <option value="1">Group 1</option>
            <option value="2">Group 2</option>
            <option value="3">Group 3</option>
            <option value="4">Group 4</option>

</select>

  </body>
</html>

Is there going to be one js file or two? Under what name?
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37826282
you don't really need any js file...simply add all the javascript in the script tag
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 37829883
Well, I am new to this. "simply add all the javascript in the script tag" may be not very simple to me.

If possible, I prefer to have html in one file and js in another. And when I run, it will do this:

When Group 2 is selected, a message to come up saying:

You clicked on Group 2

Where you put: alert("You clicked on Group 2"); additional code will be added to perform some other tasks.

Thank you,

MIke
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now