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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with dynamic PHP created forms passing to JS

Status
Not open for further replies.

jkafer

Technical User
Feb 13, 2004
32
US
I have a php page that creates forms (many on each page) with dynamically named parts.
So each form and the submit button is uniquely named.

What I want to be able to do is have the following javascript function run at the click of the button. So I need to pass the form & button name. I can do that, but I can't get the javascript to do the next thing. What I want to do is change the text(value) on the button.

This will work for 1 form.

<script type="text/javascript">
function valChange() {
document.myForm.myButton.value="Value has changed"
}
</script>

I can have the OnClick dynamically written for each button like this:
One may look like this: onClick="valChange( myForm, myButton );"

The next will look like this: onClick="valChange( yourForm, yourButton );"

How do I get it to use the variables that I am passing?
function valChange(theForm, theButton) {
How do I build the line below using the 2 variables I passed?
document.myForm.myButton.value="Value has changed"
}

I know this is something stupid that I'm not doing, but I've got a mental block on this problem now.

I appreciate any help you can give me.

Jeni
 
Use the forms and elements arrays:

document.forms[theForm].elements[theButton].value="new value";

Assuming the variables hold the names of the form and the button.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top