Jump to content

Problem with underline character in option value attribute


kenoli

Recommended Posts

I just discovered that some html code that was failing was failing because a php script I had created was inserting text that had an underline character in a value attribute in a given option tag. This occurred as I was creating a pulldown list of files in a certain directory and some of them had underline characters in their names. It took some experimentation but I discovered that whenever I put text in an option value field that had an underline as a character in the text, nothing showed up in the post variable associated with that select list. When I chose another option in that list, it showed up just fine in the post variable.Thus, this fails:<select name="something"><option value="first_item.php" >First Item</option></select>While this does not:<select name="something"><option value="firstItem.php" >First Item</option></select>What is the rule here? Are underline characters simply forbidden in value fields? Is there any work around for this?--Kenoli

Link to comment
Share on other sites

The _ character has never been an illegal character in any context, as far as I know. Just to be sure, I tried your technique, and all works fine. It SHOULD work fine. ASCII characters 0-127 are extremely consistent. The underscore character doesn't even need to be URL encoded.Are you using an unusual character encoding?Are you 100% certain it is the underscore character, and not something that just looks like an underscore? Often we get developers whose programs won't run because they mistakenly use curly quotes instead of straight quotes (thanks to Microsoft Word, usually). Could this be a similar substitution?

Link to comment
Share on other sites

Thanks for the reply. I can't figure out what is happening. I tried coding the the html directly and had the same experience you did: it worked just fine.This is how my select list is generated: A select list is generated by a function in a php object that obtains the file names by reading them from the directory they are in using a php function. The list is assigned to a php variable and passed, by a php control file, to a template that is displayed via a php include where the variable is translated into source code. The source code, once the page loads looks just fine, the same as if I had encoded it in html. But . . .When an option with a value with an underline in it is selected, it fails to show up in the post variable.I can't imagine where any odd character encoding is taking place. In the naming of the file, the object function????I know this may be a bit abstract, but is a bit hard to attach all the files involved.Any thoughts???--Kenoli

The _ character has never been an illegal character in any context, as far as I know. Just to be sure, I tried your technique, and all works fine. It SHOULD work fine. ASCII characters 0-127 are extremely consistent. The underscore character doesn't even need to be URL encoded.Are you using an unusual character encoding?Are you 100% certain it is the underscore character, and not something that just looks like an underscore? Often we get developers whose programs won't run because they mistakenly use curly quotes instead of straight quotes (thanks to Microsoft Word, usually). Could this be a similar substitution?
Link to comment
Share on other sites

I'm baffled. If the source code looks right, it shouldn't matter how it gets generated. Can you post a link, and someone here could look at the generated source? I would suggest copy/pasting some generated source, but that's not always reliable in this kind of circumstance.

Link to comment
Share on other sites

I'm baffled too. I'm going to try trouble shooting it today some more and then I'll try to send something. It is hard to send as it involves moving through a few different pages to reproduce the problem. It is actually an administrative site for another site. --Kenoli

Link to comment
Share on other sites

I figured it out. It was something in a javascript library I was using for some other purpose. I tracked down the offending script and deep sixed it and now everything works great. Thanks of taking the time to reply.--Kenoli

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...