Click to See Complete Forum and Search --> : Changing the Form Element Name?!


said_fox
07-01-2003, 06:11 PM
Hi,

I want to change the form element name. I do this for the form element value
so easy, but I can not do it for the name.
Suppose the following code:
<form name="forma">
<input type="text" name="mytxt">
<input type="button" onMouseDown="process()">
</form>
Now what can I do to change the document.forma.mytxt Name to any thing
else? using the process() as follow:
<script>
function process(){
document.forma.mytxt.value="Hello";//this is works so nice
document.forma.mytxt.name="yourtxt";// As I do Nothing
alert(document.forma.yourtxt.value);//An Error message
}
</script>
:confused: :confused:

Charles
07-01-2003, 06:49 PM
You can't go about changing the name of identifiers but you can assign an Object to a new identifier of whatever name you like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">

<script type="text/javascript">
<!--
function process (f) {
f.yourText = f.myText;
f.myText.value = 'Hello';
alert (f.yourText.value);
return false;
}
// -->
</script>

<form action="" onsubmit="return process(this)">
<div>
<input type="text" name="myText" style="display:block">
<input type="submit">
</div>
</form>