I'm not really sure how to ask this question. So, I hope you can understand by looking at my photo here.

I'm creating HTML form to grab subscriber's telephone number at first stage. Now, I want to change it by having state code in front using <select> and <option> followed by the rest of the phone number in <input>.

Eg: +6010123456789

The telephone number field has name="telephone" and id="telephone". I'm not really sure how write this. Hope you can help me with this.

2 Answers
2

first, it is best to differentiate the ID and the name attribute. Another one is something you should do with your server-side code. So, here is the example with your current data assuming this you are using native PHP using string compare and substring method.

I think you're wanting to have the selected value and the contents of the textbox be POSTed to the server as a single concatenated value, despite being two separate form fields, so that your server-side code can remain the same, reading the POST variable named "telephone"?

If that is your aim, I don't think you'll be able to leave the server-side code untouched. You could have both the <select> and the <input> with the same name attribute value, and the server-side code would receive a comma-separated value for the variable named "telephone". Without anything more complex, that's about as close as you can get.

(Remember that the <select> and the <input> cannot share an id attribute value)