Allowed characters for input element name

What characters are valid for <input> element names?
LVL 92
objectsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
cwolvesConnect With a Mentor Commented:
alpha-numeric, _

can't start with a number.  That's the requirements for it to work with most DOM models, not sure about official naming schemes.
0
 
EsopoConnect With a Mentor Commented:
Are there non-valid characters?
I guess it all depends on your character set, and what you plan to do with the input afterwards. For instance, it hapenned to me that a file not saved in UTF8 format containing "special chars" would get translated into  "weird chars" by my Unix server (some PHP in the middle). This was easily fixed by saving the file as UTF8 and declaring the same in the HTML header.

Are you having an specific problem we can help you with?
0
 
Diablo84Commented:
As far as im aware there is no standard which defines valid characters for naming inputs however if you are using it in conjunction with server side processing its advisable to follow the naming convention for variables (in the case of php atleast - which will be used upon handling the posted data) which is an underscore or a letter followed by any number/combination of letters, numbers and underscores.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
objectsAuthor Commented:
Yes, I'm starting to think its more a js problem.

I'm having problems using the following to access a form element:

objForm.MQ^15234^1^

where MQ^15234^1^ is the input element name
0
 
Diablo84Connect With a Mentor Commented:
I would imagine JS uses the same variable naming and object reference naming standards so its possible this is having an effect in the scripts functionality, is the use of the ^ characters essential? I suspect replacing them with underscores would fix the problem.
0
 
objectsAuthor Commented:
I've actually run into this problem switching it from _ (for different reasons) :)
0
 
ZylochCommented:
So call it using objForm.elements['MQ^15234^1^']?
0
 
EsopoCommented:
>>...switching it from _ ...<<
Did it not work with underscores? if so, maybe your problem is not in the variable naming but in something else related to your varaible. Maybe a duplicated name that is missleading you or something like that.

Can you post a link to your page?
0
 
objectsAuthor Commented:
> So call it using objForm.elements['MQ^15234^1^']?

thats failing

> Did it not work with underscores?

it did work with _ but that was causing problems further down the track.

> Can you post a link to your page?

no its on our development site
0
 
ZylochConnect With a Mentor Commented:
How odd. How does yours go? This is a quick thing I cooked up that illustrates my purpose:

<form name="myForm">
<input type="text" id="hi" value="Test!" name="MQ^15234^1^"><input type="button" value="Check it out!" onclick="alert(document.forms['myForm'].elements['MQ^15234^1^'].value);">
</form>
0
 
EsopoCommented:
Just to make sure, this is all client side javascript, right? If there is a server request in the middle of the process it could be an invalid chars issue. What kind of exception is it producing? Also, are you using IE? maybe a browser issue?

Did Zyloch's code work on your system?
0
 
objectsAuthor Commented:
Ended up going back to _ and doing a replace before posting to database.
Ran out of time to track down problem further so will split points between all.

Thanks for all your help :)
0
 
EsopoCommented:
Glad we could... kinda help  ;-)
0
All Courses

From novice to tech pro — start learning today.