Form logic questions (use REL or hidden input?)
I am putting together a form that will receive the telephone number of someone and store it in a database.
I have a country select and an input where they type their phone number.
When the user selects their country, I would like to append their country dialing code to the front of their phone number automatically. What is the best approach at doing something like this?
I was thinking:
A) In the country select, add a rel to each country select. For example, rel="+1"
for USA, rel="+33"
for France.
Would it be difficult for our .NET programmer to pull that information out of the select input to use?
or B) Add another select and set it to hidden, and bind the country select to the country code select so that the value changes when country is changed.
Do either of these sound like a good option or is there maybe 开发者_StackOverflowsome other means much more "enlightened" than what I have come up with?
This isn't hard at all. You don't need to bind any data
or rel
attributes at all, you can just use the value
attribute of option
s:
<select name="country_code">
<option value="+1">US (+1)</option>
<option value="+33">France (+33)</option>
</select>
<input name="phone_number" type="text" ...>
Then you can just get the full phone number on the server side by pasting together the country code and phone number. You can then check on the server side and see if the user also entered the country code into the phone field, and if so, remove it.
精彩评论