hello daniweb web developers i am beginner with programing and i want to know how to make this one..if i select a item for example CA on <select box> how to put a confirmation message that will be put in the <div> tag? i'm hoping you could help me sir..regards -aizel

<script type='text/javascript'>
function madeSelection(elem, helperMsg){
    if(elem.value == "Please Choose"){
        alert(helperMsg);
        elem.focus();
        return false;
    }else{
        return true;
    }
}
</script>
<form>
Selection: <select id='selection'>
<option>Please Choose</option>
<option>CA</option>
<option>WI</option>
<option>XX</option>
</select>
<div id"confirmation"></div>
<input type='button' 
    onclick="madeSelection(document.getElementById('selection'), 'Please Choose Something')"
    value='Check Field' />
</form>

Dani AI

Generated

For : the immediate problem is a small HTML typo and a fragile pattern. In your snippet the confirmation DIV attribute is malformed (the id needs an equals sign), and using alert() + an inline onclick makes the UI clunky. A simpler, more robust approach is to give each option a value, listen for the select's change event, and write the confirmation into the DIV (prefer textContent and an ARIA live region for accessibility).

Example (keeps JS separate from markup):

<select id="stateSelect">
  <option value="">Please choose</option>
  <option value="CA">California</option>
  <option value="WI">Wisconsin</option>
</select>

<div id="confirmation" role="status" aria-live="polite"></div>

<script>
(function () {
  var sel = document.getElementById('stateSelect');
  var out = document.getElementById('confirmation');

  function update() {
    var v = (sel.value || '').trim();
    if (v === 'CA') {
      out.textContent = 'Confirmed: California selected.';
    } else {
      out.textContent = '';
    }
  }

  if (sel.addEventListener) {
    sel.addEventListener('change', update, false);
  } else if (sel.attachEvent) {
    sel.attachEvent('onchange', update);
  }
})();
</script>

Notes and quick tips: give the placeholder option an explicit empty value to make checks predictable. Use textContent (with innerText fallback if you need very old IE) and role="status"/aria-live="polite" so screen readers announce the confirmation. Always mirror client-side checks with server-side validation. For more on the DOM APIs used see the MDN docs for addEventListener, textContent, and ARIA live regions.

i haven't seen search lol
case close

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.