0

I'm trying to automate clicking a few links on a webpage

For example, in Google Chrome if I type Javascript:setDisplayType('source'); then it runs the function in the html defined as

    <input type="radio" name="DisplayType" value="source" 
onclick="setDisplayType('source');">

So far so good. However, I'm unsure about how to do the same with the following

<td id="4124321351_U923" class="o bgc b" onclick="s(this,'329803656','40745906','9/2');b(this,'5.5','5.5');">5.5</td>

I've tried the following without success

Javascript:s(this,'329803656','40745906','9/2');

Javascript:b(this,'5.5','5.5');

Javascript:s(this,'329803656','40745906','9/2');b(this,'5.5','5.5');

Please can someone explain why it's not working and how to fire this onclick event using a similar method?

3
  • Have you tried "javascript:s(...);" Can you please provide a JSFiddle example? Commented Oct 14, 2012 at 16:45
  • You have function setDisplayType, what is b and s ? sorry, if I am not getting the right. Commented Oct 14, 2012 at 16:45
  • document.getElementById('4124321351_U923').click() ? Commented Oct 14, 2012 at 16:46

2 Answers 2

3

if you're not using JQuery or similar, then something like:

document.getElementById("4124321351_U923").click();

might work. In short, your examples above don't work because the 'this' magic variable needs to be initialised to point to the link being clicked. You could either try to initiate a click event on the element (as per my example) or you could manually grab a reference to the link, and pass that in instead of this

Sign up to request clarification or add additional context in comments.

2 Comments

I would suggest this, instead of @MuthuKamaran's answer.
I think I prefer this method as it's much simpler. Thanks
3

Problem is with this argument because it's not called from the element and you called it outside. Javascript:s(this,'329803656','40745906','9/2');

Try proving a proper argument like this, Javascript:s(document.getElementById('4124321351_U923'),'329803656','40745906','9/2');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.