File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes how to refresh captcha text with JS or render? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to refresh captcha text with JS or render?" Watch "how to refresh captcha text with JS or render?" New topic
Author

how to refresh captcha text with JS or render?

Kashif Ayyaz
Greenhorn

Joined: Nov 05, 2012
Posts: 3
I am using simpleCaptcha library to display captcha using servlet. requirement is to refresh the captcha if refresh button is pressed.

I have tried with render facility as well as using javascript but nothing is working on my end. following is my code for refresh button, captcha display and javascript function.

<h:graphicImage value="/img/refresh-s.png" onclick="changeCaptcha()" />

<f:verbatim>
<img id="myCaptcha" src="/RoyalCourtPortal-portlet/simpleImg" width="120" height="30" />
</f:verbatim>


function changeCaptcha(){
$('myCaptcha').attr('src', '/RoyalCourtPortal-portlet/simpleImg' );
}

/////////////////////////////////////////////////////////////////////////////////////////
Please while answering provide code example as I am very new with javascirpt.


Thanks in advance

regards

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15628
    
  15

http://myfaces.apache.org/tomahawk-project/tomahawk20/tagdoc/t_captcha.html


Customer surveys are for companies who didn't pay proper attention to begin with.
Kashif Ayyaz
Greenhorn

Joined: Nov 05, 2012
Posts: 3
got the solution


it was like

$("#myCaptcha").attr("src", "/RoyalCourtPortal-portlet/simpleImg?"+new Date().getTime());

instead of

$('myCaptcha').attr('src', '/RoyalCourtPortal-portlet/simpleImg?'+new Date().getTime());
or

$('myCaptcha').attr('src', '/RoyalCourtPortal-portlet/simpleImg'); as they are asp syntax styles according to my knowledge.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15628
    
  15

Hint: use the Code button in the message editor to wrap special tags around code or XML so that they will format in a more readable way.

Also, be very careful about coding "$" jQuery clauses on a JSF View Definition. The "$" may be intercepted and mis-interpreted by the EL processor, which assigns a different meaning. It's safer to use the alternate "jQuery()" syntax.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to refresh captcha text with JS or render?
 
Similar Threads
Probem in javascript in a JSF when implementing tiles in it
CAPTCHA image colors
Ajax Captcha
JavaScript is not running on IE8
Having issues using ajax to reload captcha