Creating URL via JavaScript on image click

547 views Asked by At

I am trying to call a Javascript function when an image is clicked and then send the user to a new page with appended URL values.

I have a JavaScript Function that saves the value of a hidden textbox.

<script type="text/JavaScript">
    function saveMultiSelection() {
    document.getElementById
    ('degStudLevComma').value = $("#degStudLev").
    multipleSelect('getSelects');
};
</script>

When I call the function via a standard input button the JavaScript works great. When I try to call the function via an image the JavaScript is not called.

<a href=testurl&_action=execute
%nrstr(&degStudLev=)&degStudLev
target=_blank onclick='saveMultiSelection()'><img 
src='testimage.png'/></a>
1

There are 1 answers

0
Below the Radar On

If you bind a click event listener to your image like this:

<img id="foo" src='testimage.png'/>

  document.getElementById('foo').addEventListener('click', function (e) {
     //here you can do anything you like 
     saveMultiSelection();
     window.location = 'http://www.something.com';
  });

does it works?