PDA

View Full Version : Why do tab links ignore onclick event



adibih
05-13-2008, 09:23 AM
1) Script Title: Tab Content Script (v 2.2)

2) Script URL (on DD): http://dynamicdrive.com/dynamicindex17/tabcontent.htm

3) Describe problem:

I need tab links to fill specific form input field with a predefined value when clicked on.
But I can't get it work. As if tab content script is taking exclusive rights on onclick event.
Is there a way?





<form name="myform">
<input type="text" name="targettextfield" />
</form>

<ul id="tabs" class="shadetabs">

<!-- Does not address targeted text field -->
<li><a href="#" class="selected" rel="prev1" onclick="document.myform.targettextfield.value='new value';">tab 1</a></li>

<li><a href="#" rel="prev2">tab 2</a></li>

</ul>

<!-- This works as expected -->
<a href="#" onclick="document.myform.targettextfield.value='new value';">js test 1</a>

jscheuer1
05-13-2008, 09:30 AM
It does take control over, basically writes, the onclick event itself. If there is one already, it overwrites it. You could change your event to one of the following, whichever works out best for you, but if onclick was your first choice, onmousedown is probably the next best thing:

onmousedown
onmouseup
onmouseover
onmouseout

ddadmin
05-13-2008, 10:33 PM
Or, you can change the Tab Content script to use the onmousedown event instead of onclick to select the tabs, leaving the later open. Inside the .js file, change the highlighted part to the new value in red:


this.tabs[i].onmousedown=function(){
tabinstance.expandtab(this)
tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
return false
}