Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use JavaScript Variable on Java/ Can I get input text in Java

Status
Not open for further replies.

otamez

Programmer
Jul 4, 2003
3
MX

When a user click a button I call a Java Script function "validateFields".

In this funciont I do some validations, regarding what they typed on the Input Text.

I have a value in variable X that I need to use it on Java, because I also use Java in this function in order to process some activities.

Regarding this I have two questions to solve this problem
There is a way to call the JavaScript variable in Java?
There is a way that in Java I could get the value typed in the Input Text?

I hope I explaned my self.

Thanks in advance.
 
Use HTML as an interface for JavaScript and JSP ....

Eg - to set the HTML to a value from JSP ::

<INPUT TYPE=&quot;text&quot; NAME=&quot;myName&quot; VALUE=<%= myJSPValue %>

And to access it via JavaScript ...

alert(myName.value);

 
yup like sedj says u can access it like that or better u can access it in javascript itself:
<script>
alert('<%=value%>')
</script>

Known is handfull, Unknown is worldfull
 
Your explanation help.

I will explain the case in order to clarify it, I think I was not so clear while explaining the problem.

</script>
<script language=&quot;Javascript&quot;>
function DateValidation()
{
var myVariable;
// How can I get the typedDate value in Java like is shown in the next line

<%
String sTypedDate=document.formname.typedDate.value;
// Date Format typed 07/14/2003
String sDay;
sDay=sTypedDate.substring(3,5); //14

....other Java Code.

%>
//How can I use the sDay Java Variable in JavaScript
myVariable = sDay;

.. Other JavaScript Code

}

</script>

<body>
<input type=&quot;text&quot; name=&quot;typedDate&quot; >
<input type=&quot;button&quot; name=&quot;ValidateDate&quot; value=&quot; Date Validation &quot; onClick=&quot;Javascript:DateValidation();&quot;>
</body>
 
change myVariable = sDay; to:
myVariable = <%=sDay%>;

that ought to do it...


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top