Solved

javascript on click

Posted on 2014-09-24
7
148 Views
Last Modified: 2014-09-25
When toner is onclick, I want to capture 'name' and 'brand'. how can I code in javascript?
Below codes is in ascx and within master page with form name: form1


      <select name="brand">
        <option value="HP">HP</option>
        <option value="Canon">Canon</option>
      </select>
      <a href="Category.aspx?name=Toner"" id=">Toner</a>
0
Comment
Question by:ITsolutionWizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40342908
test page : http://jsfiddle.net/h5m6vusm/
please note I added ID attribute to the elements

window.onload = function() {
   document.getElementById("toner").onclick = function() {
         var brand = document.getElementById("brand");
         brand = brand.options[brand.selectedIndex].value;
         // checking :
         alert( brand );
   }
}

Open in new window

0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40342920
not working. please provide complete codes link included jquery.
And I want to redirect to category.asp not alert. thanks,
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40342923
what do you mean by "not working" ?
do you mean on your side ? did you read all my comment regarding the ID ?
could you provide a link to your page to check ?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40342945
<a href="Category.aspx?name=Toner"" id=">Toner</a> and I want to get value from name as well. maybe I should rename to productType=Toner
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40342954
<asp:DropDownList runat="server" ID="brand">
                                                <asp:ListItem selected="True" Text="HP" Value="HP"></asp:ListItem>
                                                <asp:ListItem Text="Canon" Value="Canon"></asp:ListItem>
                                            </asp:DropDownList>



<asp:DataList Width="800px" runat="server" ID="dataListBrand" RepeatColumns="8" RepeatDirection="Vertical" >
                                            <ItemTemplate>
                                             <li>
                                             <a href="Brand.aspx?Name=<%# Eval("name") %>">
                                             <asp:Label Width="140px" runat="server" ID="repeatListItemCategory" Text='<%# Bind("name") %>'></asp:Label>                                            
                                             </a>
                                             </li>
                                            </ItemTemplate>
                                            </asp:DataList>        



Let me put the exact codes for you to review.

If <a href="Brand.aspx?Name=<%# Eval("name") %>"> is clicked, it is a link then I
want to capture both values from <a href="Brand.aspx?Name=<%# Eval("name") %>"> and brand.

Sorry for any confuse.
0
 
LVL 2

Accepted Solution

by:
Vishal Patil earned 500 total points
ID: 40343645
Hello  ITsolutionWizard,

Please check with following code:

Javascript:
    <script type="text/javascript">
        function SayHello(txt, contact) {
            document.getElementById("<%= brand.ClientID %>");
            alert(document.getElementById("<%= brand.ClientID %>").value);
            alert(txt);
            window.open(contact, "Tesst");
            return false;
        }
    </script>

Open in new window


Source :

<asp:DropDownList runat="server" ID="brand">
        <asp:ListItem Selected="True" Text="HP" Value="HP"></asp:ListItem>
        <asp:ListItem Text="Canon" Value="Canon"></asp:ListItem>
    </asp:DropDownList>
    <asp:DataList Width="800px" runat="server" ID="dataListBrand" RepeatColumns="8" RepeatDirection="Vertical">
        <ItemTemplate>
            <li><a href="" onclick='javascript:return SayHello("<%# Eval("name") %>","Brand.aspx?Name=<%# Eval("name") %>");'>
                <asp:Label Width="140px" runat="server" ID="repeatListItemCategory" Text='<%# Bind("name") %>'></asp:Label>
            </a></li>
        </ItemTemplate>
    </asp:DataList>

Open in new window

0
 
LVL 1

Author Closing Comment

by:ITsolutionWizard
ID: 40344661
quick and accurate
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 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