How do I fill a field of a page in cURL which does not send the data via form, but via Javascript?
The page in question is this:
<script type='text/javascript' src='js/juridico.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<script type='text/javascript' src='dwr/interface/ValidacaoCaptchaAction.js'></script>
<!-- Início do include do captcha para qualquer página -->
<script type="text/javascript" language="Javascript1.1">
var popup = true;
if (window.dialogArguments) { // IE
window.opener = window.dialogArguments;
}
window.onload = load;
window.onbeforeunload = unload;
function validaNumeroCaptcha(e){
var unicode=e.charCode? e.charCode : e.keyCode;
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)(127=DEL Key)
if (unicode<48||unicode>57) //if not a number
return false; //disable key press
}
document.getElementById("mensagem").innerHTML = " ";
return true;
}
function setTextoCaptchaFocus(){
document.getElementById('captcha_text').focus();
}
function recarregaImagem(){
document.getElementById('captcha_image').src = "imagens/icon_wait.gif";
var ran_number = Math.random()*5;
var captcha_servlet = "captcha.svl?" + ran_number;
document.getElementById('captcha_image').src = captcha_servlet;
document.getElementById('captcha_text').value = "";
document.getElementById('captcha_text').focus();
}
function gerar()
{
recarregaImagem();
}
function load(){
if (window.opener)
{
window.opener.document.body.style.opacity = 0.4;
window.opener.document.body.style.filter = "filter: alpha(opacity=40)";
}
setTimeout("gerar()", 1000);
}
function unload()
{
if (window.opener)
{
window.opener.document.body.style.opacity = 1;
window.opener.document.body.style.filter = "filter: alpha(opacity=100)";
}
var vReturnValue = new Object();
vReturnValue.captcha_text = document.getElementById("captcha_text").value;
window.returnValue = vReturnValue;
}
function verificaNumero(campo)
{
if (campo.value.length == 5)
{
ValidacaoCaptchaAction.isCaptchaValid(campo.value, ret);
}
}
function ret(valido)
{
if (valido)
{
window.document.getElementById("captcha_text").style.display = "none";
window.document.getElementById("wait").innerHTML = "Aguarde...";
window.document.getElementById("wait").style.display = "inline";
if (window.document.getElementById("linkCaptcha"))
{
document.location.reload(true);
}
if (window.opener && popup)
{
window.close();
}
}
else
{
document.getElementById("mensagem").innerHTML = "O número digitado não corresponde à imagem exibida. Favor informar o código novamente.";
gerar();
return false;
}
}
</script>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/css/layout.css" rel="stylesheet" type="text/css" />
<link href="/css/tjmg2007.css" rel="stylesheet" type="text/css" />
<title>Captcha</title>
</head>
<body style="background-color: white;">
<div id="mensagem" style="color: #FF0000; font-weight: bolder; text-align: center;"> </div>
<table border="0" width="100%">
<tr>
<td class="medio" align="center" colspan="2">Digite os números abaixo:</td>
</tr>
<tr>
<td align="right" valign="middle" width="60%">
<img id="captcha_image" src="imagens/icon_wait.gif" onclick="javascript: setTextoCaptchaFocus()" align="middle">
</td>
<td width="40%" align="left">
<input type="text" id="captcha_text" name="captcha_text" value="" size="5" maxlength="5" onkeypress="return validaNumeroCaptcha(event);" onkeyup="return verificaNumero(this);" onkeydown="if (popup && (getBrowser() == 'safari' || getBrowser() == 'opera')) return false;" class="campo_form" autocomplete="off">
<div id="wait" style="display: none;"/>
</td>
</tr>
<tr>
<td class="pequeno" align="center" colspan="2">
<a href="javascript: recarregaImagem()" id="gerar">Gerar nova imagem</a> -
<a href="captchaAudio.svl" onclick="javascript: setTextoCaptchaFocus()">Escutar o código</a>
</td>
</tr>
<tr>
<td class="pequeno" align="center" colspan="2">
<br>Caso a imagem não apareça, clique em 'Gerar nova imagem'.
</td>
</tr>
</table>
</body>
When you have forms handling, just use CURLOPT_POSTFIELDS, but in this case you do not have, how to proceed?