I have two selectboxes which are driven from database both select boxes references the same table, the table has three columns id, from, to ;selectboxes work ok what i want is to get the id of the selected record without refreshing the page.

Dani AI

Generated

Brief summary and practical options. The table has columns id, from, to and the page already fills two selects from that table. suggested Dreamweaver dynamic fields and reports that didn’t meet the need. There are three reliable ways to get the record id client‑side without a full page reload:

  1. Render the id into each option (simplest)
    When you build the selects on the server, make each <option> carry the row id as its value. Reading the selected id is then immediate in JavaScript.
<select id="fromSel">
  <option value="12">London</option>
  <option value="13">Paris</option>
</select>

<script>
var id = document.getElementById('fromSel').value; // id is "12" or "13"
</script>
  1. If the id depends on a pair (from + to), preload a small map
    If the selected record is the one where both from and to match, the page can emit a JSON map at render time so no extra round trip is needed. This is fast and keeps the UI snappy.
<script>
var map = {"London|Paris": 42, "Paris|Rome": 43};
var id = map[fromValue + '|' + toValue];
</script>
  1. AJAX lookup (keeps page light if many combinations)
    On change, send the two selections to a server endpoint (get_id.php) that returns JSON { "id": 42 }. Use fetch or XMLHttpRequest, then update the UI when the response arrives.
fetch('get_id.php?from='+encodeURIComponent(f)+'&to='+encodeURIComponent(t))
  .then(r=>r.json()).then(data => console.log(data.id));

Debug and safety tips: inspect the generated HTML with browser devtools to confirm value attributes; console.log your selections before calling the server; validate and use prepared statements server‑side; return JSON with proper headers. If using Dreamweaver, it can generate the server code but client scripting (mapping or AJAX) is usually hand‑added for this dynamic lookup.

Recommended Answers

All 3 Replies

u will have to use a dynamic field for that and link it to the database therefore giving u the value straightaway... in dreamweaver check dynamic form fields

u will have to use a dynamic field for that and link it to the database therefore giving u the value straightaway... in dreamweaver check dynamic form fields

thanks for advice but ı have tried this in dw already couln't get it work. also i dont think dw has the capability of this by default components

Well i have attached a screenshot of how to set it up in dreamweaver.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.