?
Solved

javascript on click

Posted on 2014-09-24
7
Medium Priority
?
150 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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