Closed Thread Icon

Preserved Topic: form element has a hyphen... oh dear... Pages that link to <a href="https://ozoneasylum.com/backlink?for=18365" title="Pages that link to Preserved Topic: form element has a hyphen... oh dear..." rel="nofollow" >Preserved Topic: form element has a hyphen... oh dear...\

 
Author Thread
sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 11-10-2001 19:38

I have a page that when you click on tickboxes, it updates a textarea. I'm working with someone elses CGI and cannot change form or element "names". As you'll see, I have 'document.messaging.X-E3-Recipients.value' and JS falls over because of the hyphens (it must thing I mean "minus"). (messaging is the form name, X-E3-Recipients is the textarea name.)

How can I get round this??


<SCRIPT type="text/javascript">
<!--
function putText(addText) {
var addText;
var revisedMessage;
var currentMessage = document.messaging.X-E3-Recipients.value;
revisedMessage = currentMessage+addText;
document.messaging.X-E3-Recipients.value = revisedMessage;
document.messaging.X-E3-Recipients.focus();
return;
}
//-->
</SCRIPT>

----------------

<table>
<tr>
<td>Click the tick box...</td><td><input onClick="putText('this text should appear');" type="checkbox"></input></td>
</tr>
</table>

----------------

<TEXTAREA cols="50" rows="5" name="X-E3-Recipients" wrap="virtual"></textarea>

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 11-10-2001 20:13

got it.. used

document.messaging[1].value sort of thing.. seems to have worked fine...

:-)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 11-10-2001 20:36

Yeah, you could probably also have used document.messaging["X-E3-Recipients"].value too. But whoever created a form with hyphens in the name was an idiot.

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 11-10-2001 23:40

Yeah Slime.. hyphens in code - pretty bad practice... while you're here....

If I do...

var MobileNumberA = 0123456789

and then call that variable later.. it drops off the first zero...

how can I preserve my 0?

cheers,

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 11-11-2001 00:15

I think you want to set it to a *string* - "0123456789". It's a litle complicated how strings and numbers work in javascript.

hlaford
Bipolar (III) Inmate

From: USA! USA! USA!
Insane since: Oct 2001

posted posted 11-13-2001 17:06

I couldn't disagree more about the use of hyphens in HTML. Since the standard clearly supports them, one would be ignorant to discount their use at all times.

"accept-charset" and "http-equiv" are examples that I can think of off-hand. In fact, using hyphens in names can alleviate problems with long names by making them more readable.


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 11-13-2001 18:28

Sure, hyphens are allowed in HTML. They're not allowed in JavaScript variable names, however, and when you're setting the name of a form element, you're setting it's JavaScript variable name. That, I think, is the only place that hyphens aren't allowed in HTML - since it's not *really* HTML inside the name="jsvarname" quotes. No more than init() is HTML within onload="init()".

Then again, if you're sure you're never going to use the form with JavaScript, then it doesn't matter, since it will work anyway. But as Sonicsnail just showed us, you can never be sure of that.

hlaford
Bipolar (III) Inmate

From: USA! USA! USA!
Insane since: Oct 2001

posted posted 11-26-2001 22:33
code:
<form name="my-form">
<input name="my-element" value="hi" />
</form>
<script>
alert(document["my-form"]["my-element"].value);
</script>



« BackwardsOnwards »

Show Forum Drop Down Menu