I have a drop down menu. I use it to select a particular Tea.
JavaScript
x
11
11
1
<form name="barcode" onSubmit="return OnSubmitForm();" method="post">
2
3
<select name="entry_id" id="entry_id">
4
<option selected="selected">Select a tea</option>
5
<td><option entry_id="865"> Black Tea</option></td>
6
<td><option entry_id="123"> Green Tea</option></td>
7
</select>
8
9
<input type="submit" value="Tea story">
10
</form>
11
Then I want to use javascript to retrieve entry_id
of the selected Tea and append the it to end of the URL, e.g. /myshop/tea/865
<– 865 is the entry id for Black Tea
My Javascript code:
JavaScript
1
10
10
1
<SCRIPT language="JavaScript">
2
function OnSubmitForm()
3
{
4
alert('inside');
5
var eid = document.getElementById('entry_id').value;
6
alert(eid);
7
document.barcode.action ="https://www.myshop.ca/tea/" + eid;
8
}
9
</SCRIPT>
10
But every time it append “Black Tea” or “Green Tea” names, e.g, /myshop/tea/Black Tea
or /myshop/tea/Green Tea
. Is there a way to append entry_id
at the end of the URL, e.g. /myshop/tea/865
or /myshop/tea/123
Advertisement
Answer
JavaScript
1
11
11
1
<form name="barcode" onSubmit="return OnSubmitForm();" method="post">
2
3
<select name="entry_id" id="entry_id">
4
<option selected="selected">Select a tea</option>
5
<option value="865">Black Tea</option>
6
<option value="123">Green Tea</option>
7
</select>
8
9
<input type="submit" value="Tea story">
10
</form>
11
makes more sens. use the form widgets as they are supposed to be used.