how do I get The value I have entered in a textfield after submitting it. i need to process it using java

thanks

Get the value AFTER you submit it? That would be a server-side question. Since you mention Java, I suggest you ask in the Java forum. All values are packaged in the RESPONSE object, but that object is exposed in different ways in different languages.

opps i i want to get it using javascript.

hehehe

<script type="text/javascript">
    var theText = document.forms[0]["txtFieldName"].value;
</script>

That's how to reference a control in an HTML form, but after you submit? I don't get it. More info required.

If the text element has an ID, as it should it XHTML, the DOM method is: document.getElementById['myId'].value I'm not sure what you're hinting at by "after the submit", though, in your question.

That won't work with square brackets, but with parentheses that is fine.

Both our methods are the best cross browser methods. As long as you avoid document.all or document.txtFieldName you should be ok.

I'm not sure what you're hinting at by "after the submit", though, in your question.

Well Covinus said:

how do I get The value I have entered in a textfield after submitting

And I'm trying to think of why would you want to reference a control in client side script after a submit? perhaps the submit is irrelevant in this case and a red herring just to keep us on our toes!

here is what i remember about my code.

var a = document.formname.textname.value generates an error mesasge

everytime i add this to my code nothing appears.
but when i remove the other stuff comes out.

do you really need the semicolon in last line??? i found books that dont have ; in the end

JavaScript uses the semi-colon for line-termination. For the proper method(s) of placing the value of a textbox into a variable, please refer to the posts from myself and hollystyles in this thread.

If you have new, different questions about JavaScript, please start a new thread.

do you really need the semicolon in last line??? i found books that dont have ; in the end

It is true some browsers will run javascript without ; line terminators. But it is bad practice because the ECMA standard states ; is required and browser implimentations could change in the future. So any script you write without them, may work now but could be rendered useless after a browser upgrade.

I would say if you have books that omit ; they are out-of-date or just poor. If you can get hold of it in the Philippines I recommend the Javascript Anthology by James Edwards and Cameron Adams published by Sitepoint ISBN 0-9752402-6-9

<html>
<head>
<title>
hi!!!
</title>
<script type="text/javascript">


function operator(op){
if(op==0)
return "+"
if(op==1)
return "-"
if(op==2)
return "x"
else
return "/"
}
    function add(n1, n2, n3, n4){
    var ans
    if(n3==0){
    ans=n1+n2
    if(ans ==n4)
    alert("you got it right!")
    else
    alert("Sorry its wrong. the answer is: "+ans)
    }
    if(n3==1){
    ans=n1-n2
    if(ans==n4)
    alert("you got it right!")
    else
    alert("Sorry its wrong. the answer is: "+ans)
    }
    if(n3==2){
    ans=n1*n2
    if(ans ==n4)
    alert("you got it right!")
    else
    alert("Sorry its wrong. the answer is: "+ans)
    }
    if(n3==3){
    ans=n1/n2
    if(ans ==n4)
    alert("you got it right!")
    else
    alert("Sorry its wrong. the answer is: "+ans)
    }
    }
    
    
    
</script>
</head>
    <body>
    <font color="black" size="7"><center>
    <script type="text/javascript">
    
    
    var num1=(Math.floor(Math.random()*11))
    
    var num2=(Math.floor(Math.random()*11))
    
    var operation=(Math.floor(Math.random()*3))
    
    var convertedOp=operator(operation)
    
    document.write(num1 + "<br>" + convertedOp+ " <br>" + num2 + "<br>")
    document.write("______")
    var answer=document.form1.tfield.value;
    
    
    function check(){
    
    add(num1,num2,operation,answer)
    }
    </script>
    <form action="test.html" name="pormas">
    <input type="text" size=3 name="tfield" id="ans" value=0><br>
    <input type="button" value="Answer" name="ans" onclick="return check()">
    </form>
    
</body>
</html>

this is my code for generating a number and do an operation randomly too. but i cant get the user input so i cant process it. it seems that the answer variable is always undefined.

we both have the same problem..getting the data from the text field inorder for us to compare it and generate it in a function..

Number one READ what we are telling you.
1. PUT ; at the end of your statements.
2. replace var answer=document.form1.tfield.value; with what we told you THREE times now var answer=document.getElementById['tfield'].value Now this line var answer=document.form1.tfield.value; is not only syntacticly wrong, it's in the wrong place. It will get parsed and executed by the browser BEFORE the text box "tfield" exists in the DOM (Document Object Model) so instead you need to move it into function Check()

And you have this bit wrong <input type="text" size=3 name="tfield" id="ans" value=0> it should be <input type="text" size=3 name="tfield" id="tfield" value=0> You can't reference the textbox by name, you must use the ID.

this code works

<html>
<head>
<title>
hi!!!
</title>
<script type="text/javascript">


function operator(op){
if(op==0)
return "+";
if(op==1)
return "-";
if(op==2)
return "x";
else
return "/";
}
function add(n1, n2, n3, n4){
var ans;
if(n3==0){
ans=n1+n2;
if(ans ==n4)
alert("you got it right!");
else
alert("Sorry its wrong. the answer is: "+ans);
}
if(n3==1){
ans=n1-n2;
if(ans==n4)
alert("you got it right!") ;
else
alert("Sorry its wrong. the answer is: "+ans);
}
if(n3==2){
ans=n1*n2 ;
if(ans ==n4)
alert("you got it right!")
else
alert("Sorry its wrong. the answer is: "+ans) ;
}
if(n3==3){
ans=n1/n2  ;
if(ans ==n4)
alert("you got it right!") ;
else
alert("Sorry its wrong. the answer is: "+ans);
}
}



</script>
</head>
<body>
<font color="black" size="7"><center>
<script type="text/javascript">


var num1=(Math.floor(Math.random()*11));

var num2=(Math.floor(Math.random()*11));

var operation=(Math.floor(Math.random()*3));

var convertedOp=operator(operation);

document.write(num1 + "<br>" + convertedOp+ " <br>" + num2 + "<br>");
document.write("______");



function check(){
var answer=document.getElementById("tfield").value;
add(num1,num2,operation,answer) ;
}
</script>
<form action="test.html" name="pormas">
<input type="text" size=3 name="tfield" id="tfield" value=0><br>
<input type="button" value="Answer" name="ans" onclick="return check()">
</form>

</body>
</html>

sorry..

ok i get it

function b1(){

    var val=document.getElementsById("t1").value;

        $('#i1').rotate({maxAngle:360,minAngle:0,
        bind: [
                {"mouseover":function(){$(this).rotateAnimation(122);}},
                {"mouseout":function(){$(this).rotateAnimation('val');}}
              ]
                    });
                }

i want to rotate my image using java script.i put some value in text field i.e. #t1
and call the value of the text field into the rotateAnimation function.
is this possible pl help ..........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.