Solved

javascript on click

Posted on 2014-09-24
7
137 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
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
 

Author Comment

by:ITsolutionWizard
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:ITsolutionWizard
Comment Utility
<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
 

Author Comment

by:ITsolutionWizard
Comment Utility
<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
Comment Utility
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
 

Author Closing Comment

by:ITsolutionWizard
Comment Utility
quick and accurate
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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…
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 …

772 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

10 Experts available now in Live!

Get 1:1 Help Now