How to read the value of a readonly field?

Asked

Viewed 142 times

3

I’m trying to read the value of a readonly field, but I’m not able to access its value, it doesn’t have the value in html only appears in the browser.

inserir a descrição da imagem aqui

 <form id="form1" name="form1">
    <p>Numero 1</p>
    <input type="text" name="numero1" id="numero1" readonly="">
    <p>Numero 2</p>
    <input type="text" name="numero2" id="numero2" readonly="">
    <div><p>a soma dos numeros é</p>
    <input type="text" name="soma" id="soma">
    <p>a subtração dos numeros é</p>
    <input type="text" name="subtraca" id="subtracao">
    </div>
    <input type="button" value="Realizar Operacao" id="Operacao" name="Operacao" onclick="startOperacao()">

    <h3>Resultado</h3>
    <div id="divResult" name="divResult">

    </div>
    <div style="width:500px;visibility: hidden;" id="divNext">
                    <p style="text-align:right;">
                        <input type="button" id="Submit" name="Submit" value="Próxima Tarefa" class="btn btn-primary" onclick="nextStep();">
                    </p>
    </div>              
    </form>

I’ve tried using the;

 var numero1 = doc.GetElementById("numero1");

and the InnerHtml comes void.

I’m using webBrowser.

Has some way of reading the value ?

Field completion.

<script>
function start()
{
document.form1.numero1.value = parseInt(Math.random()*10000);
document.form1.numero2.value = parseInt(Math.random()*10000);
}
function startOperacao()
{
var numero1 = parseInt(document.form1.numero1.value);
var numero2 = parseInt(document.form1.numero2.value);

var somaEntrada = parseInt(document.form1.soma.value);
var subtracaoEntrada = parseInt(document.form1.subtracao.value);

var soma = numero1 + numero2;
var subtracao = numero1 - numero2;

var textoResposta='';
if(soma==somaEntrada && subtracao==subtracaoEntrada)
{
    textoResposta= 'O Primeiro numero é: ' + numero1 + '\nO Segundo numero é:' + numero2 + '\nA soma é:' + soma + '\nA Subtração é ' + subtracao + '\nOs resultados que você colocou estão corretos';
    document.getElementById('divNext').style='width:500px;visibility: display';
}
else{
    textoResposta = 'O resultado não está certo. você deve fazer a Soma e a Subtração e colocar nos lugares corretos';
    document.getElementById('divNext').style='width:500px;visibility: hidden';
}
document.getElementById('divResult').innerText = textoResposta;

}
function nextStep()
{
    setTimeout(function () {
       window.location.href = "entrada.php"; //will redirect to your blog page (an ex: blog.php)
    }, 2000);
}
</script>
  • 1

    Only by guarantee could post how the field is completed, in function: startOperacao()

  • 1

    @Caiqueromero edited.

  • removes parseint and performs a test

  • 1

    @Caiqueromero, this is not my site, and I don’t have access to it, I’m using webBrowseer with windows Forms C#.

  • https://stackoverflow.com/questions/10091938/get-value-from-read-only-input-with-c-sharp-web-browser

1 answer

1


I found a similar question on ONLY see if it fits you:

dynamic elePrice = webBrowser.Document.GetElementById("price").DomElement;
string sValue = elePrice.value;

Or if you can’t use dynamic try

mshtml.IHTMLInputElement elePrice =(mshtml.IHTMLInputElement)webBrowser.Document.GetElementById("price").DomElement;
string sValue = elePrice.value;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.