Solved

javascript on click

Posted on 2014-09-24
7
141 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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
 

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
 

Author Closing Comment

by:ITsolutionWizard
ID: 40344661
quick and accurate
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

895 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

11 Experts available now in Live!

Get 1:1 Help Now