Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can I set onclick to a function with parameters

    I am using an initialization function that reads an XML document to create the HTML document. One part of my HTML document should look like this.
    Code:
    <a class="parentTopic" href="#" onClick="changeState(5)" onDblClick="changeState(6)">
        <span class="topicText">Course Dates</span><span class="topicArrow">4</span>
        <div class="outline">
    	<div class="outlineTopic">Course Launch Date/Next Course </div>
    	<div class="outlineTopic">Book Shipment Date/Next Book Shipment Date</div>
    	<div class="outlineTopic">Shipping Blackout Period</div>
        </div>
    </a>
    note the onClick event has a function with a parameter attached to it. But in JS i know you can do [element].onClick = [function], but doing that doesn't allow you to send in a parameter. How on earth do you set the onclick event to a function with a parameter?

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Depends where the parameter is coming from and what it is...

    One way would be (passing an object reference):
    element.onclick = new Function("function(this)");

    Another would be (passing a parameter with quotes):
    element.onclick = new Function("function('"+parameter+"')");

    Passing a variable without quotes:
    element.onclick = new Function("function("+parameter+")");

    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •