This week's book giveaway is in the Python forum.
We're giving away four copies of High Performance Python for Data Analytics and have Tiago Rodrigues Antao on-line!
See this thread for details.
Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

assign values to form elements dynamically?

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will invoke a java script method with arguments 1.form element name and 2.a String value which has to be assigned to that form element.

Can any one tell me how to do that?
i have done but it is giving error..
eg:--

<html>
<head>
<script type="text/javascript">
function convertText(element,value) {
document.SampleForm.element.value = value;
}
</script>
</head>
<body>
<form name="SampleForm">
<input type="text" name="myText">
<input type="button1" value="Convert" on click="convertText(button1,'Converted')">
<input type="button2" value="Convert" on click="convertText(button2,'Converted')">
<input type="button3" value="Convert" on click="convertText(button3,'Converted')">
<input type="button4" value="Convert" on click="convertText(button4,'Converted')">
</form>
</body>
</html>

i.e. when i click button1.....button1 value must change from convert to Converted..and similarly for other buttons..
which ever button i click its value must change to the value i passed as argument to the method.
[ August 19, 2007: Message edited by: Bear Bibeault ]
 
Marshal
Posts: 67497
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Abhishek Reddy Chepyala:

i have done but it is giving error..



What error? How can you expect help to resolve the error if you don't tell us what it is?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you posted

is looking for a form element named element. In order to use an array, you need to use the elemetns array.

Eric
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply....iam looking for this

document.SampleForm.elements[element].value

thanks alot i got my problem solved...one more thing i want is once the button is clicked and after its value changed to Converted i want to disable that button.
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks i got that one
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i can able to disable the button and at the same time i want to display an image on the disabled button....can any one tell me how to do this.

document.main.elements[element].disabled=true;
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam facing problem in hiding the form elements.The below code is working perfectly fine in InternetExplorer....but it is not working in mozilla firefox...can anyone tell me how to overcome this problem..

what iam doing is when the button value is changed from convert to converted
iam displaying an image beside the button...

<html>
<head>
<script>
function doThis(one,tick)
{
document.main.elements[one].value="added";
document.main.elements[one].disabled=true;
document.main.elements[tick].style.display="block";
}
</script>
</head>
<body>
<form name="main" action="get">
<img id="tick1" src="tick.gif" style="display:none"/><input type="button" name="one" value="add" on click="doThis('one','tick1')"/>
<img id="tick2" src="tick.gif" style="display:none"/><input type="button" name="two" value="add" on click="doThis('two','tick2')"/>
<img id="tick3" src="tick.gif" style="display:none"/><input type="button" name="three" value="add" on click="doThis('three','tick3')"/>
<img id="tick4" src="tick.gif" style="display:none"/><input type="button" name="four" value="add" on click="doThis('four','tick4')"/>
</form>
</body>
</html>
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An img tag is not a form element. You need to reference that via

document.getElementById(tick).style.display="block";"

Eric
 
Abhishek Reddy
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot it worked fine..
one more thing is there any way to display the image on the button..
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic