Solved

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

Posted on 2009-05-04
3
1,644 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

11 Experts available now in Live!

Get 1:1 Help Now