Then you should provide that information up front. There are a lot of people that are new to coding that come to this forum and, many times, they are asking for a solution that is a bad one and will set a bad precedent for their learning. So, when responding to requests I feel obligated to prevent propagating bad habits before they start. But, what you said still makes no sense. There should be nothing in the HTML code for the product and/or price other than an ID for the product and the quantity. But, no matter, you think you know what you are doing so I'll give you a potential solution. Just give me a URL to the site so I can go and purchase whatever they are selling and I can change the price to $0.01
Use an onchange trigger to take the value of the select field as you currently have it and split() the string based upon the dash. If any product names can contain a dash then you would have to use logic to split it only at the last dash. Then take those two values and populate into the hidden fields.
<html>
<head>
<script type="text/javascript">
function populateNamePrice(value)
{
var name, price;
if(value=='')
{
document.getElementById('name').value = '';
document.getElementById('price').value = '';
return
}
var value_parts = value.split(' - ');
document.getElementById('name').value = value_parts[0];
document.getElementById('price').value = value_parts[1];
return;
}
</script>
</head>
<body>
Select a product:
<select name="product" id="product" onchange="populateNamePrice(this.value);">
<option value="">-- Select a Product --</option>
<option value="Product 1 - 1.00">Product 1 - 1.00</option>
<option value="Product 2 - 2.00">Product 2 - 2.00</option>
<option value="Product 3 - 3.00">Product 3 - 3.00</option>
<option value="Product 4 - 4.00">Product 4 - 4.00</option>
<option value="Product 5 - 5.00">Product 5 - 5.00</option>
<option value="Product 6 - 6.00">Product 6 - 6.00</option>
</select>
<br><br>
Name: <input type="text" name="id" id="name" readonly="readonly"><br>
Price: <input type="text" name="price" id="price" readonly="readonly"><br>
</body>
</html>