Forum Moderators: open

Message Too Old, No Replies

change text box name

         

dragon master mokuba

8:32 am on Jul 17, 2008 (gmt 0)

10+ Year Member



is it possible to change the name of a text box with javascript

For example:


<input size="10" name="u1_prizes[p_101]">

To:


<input size="10" name="u1_prizes[p_102]">

Fotiman

1:58 pm on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you have a reference to the element, just set the name value. As in:

el.name = "u1_prizes[p_102]";

I tried this in Firefox 2 and IE7 and it worked in both.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>Untitled</title>
</head>
<body>
<form action="">
<div>
<input id="foo" name="bar">
<input type="submit" value="submit">
</div>
</form>
<!-- Scripts -->
<script type="text/javascript">
window.onload = function() {
var el = document.getElementById('foo');
el.name = 'u1_prizes[p_102]';
};
</script>
</body>
</html>

dragon master mokuba

3:40 pm on Jul 17, 2008 (gmt 0)

10+ Year Member



Thanks! Wasnt sure if there was a property like that. It works wonderfully =D