Solved

How to let HTML input text value from javascript function call return value?

Posted on 2009-05-04
3
1,645 Views
Last Modified: 2013-11-19
I have a HTML page with form and various input fields. However, the default value of some input fields should be calculated dynamically from return value of some java script. Also when the submit type button is clicked, all input fields should be validated before invoking the sever side PHP script. Could someone tell me how to do it? Thanks!
0
Comment
Question by:gs_kanata
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 400 total points
ID: 24301062
You are going to have to supply more information.  For example, what kind of fields, and what kind of validation.  It is quite common to see a form tag something like this:

When the submit button is clicked, the specified function (in this case validateFormOnSubmit() ) is called to check for valid values in each of the form elements.

If the values are acceptable, the function returns a value of true, and the action event will be used.  Otherwise a value of false is returned, and the user  is able to correct the issues.
<form name='myForm' onsubmit='return validateFormOnSubmit(this)' action='target.html'>

Open in new window

0
 
LVL 4

Assisted Solution

by:bleach77
bleach77 earned 100 total points
ID: 24302295
Write a function that will change the value. Something like this:

document.myForm.txtbox.value = "New Value";

Call the function like HonorGod post. The javascript will change the value before submitting the form.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24408468
Thanks for the grade & points.  I'm sorry that you didn't feel the answer warranted an A.

Good luck & have a great day.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now