• 0

[PHP/Ajax] ComboBox "SelectedItem change" event


Question

  • 0

You could go with an AJAX solution or just JS. If you want to do AJAX, it'll require downloading the content as the options are selected; with just JS, all the HTML will be loaded and displayed accordingly using CSS (initially).

For JS, based on the selected item, you would display a specific div while hiding the other ones.

Are you using a JS framework?

4 answers to this question

Recommended Posts

  • 0

I'm not using JS framework.....

but I think I little figure out how it will look like, but the code still doesn't work :(

<Option VALUE="Item3" onChange="Show();">3</option>

Where Show() is a JS function defined, I don't know how to deal with a combobox throught the function, how could I tell it:

If cboAct.Selecteditem = "Item3" then MyDiv.visible = false ........ something like that

I still didn't tested if onChange event works with each item not for the entire combobox.

  • 0

Thanks all for your help, I managed to do it finally, It will be as follows :)

&lt;script language="JavaScript"&gt;&lt;!--
function T1(object) {
if (object == "Item3")
	{
	document.getElementById('myId').style.visibility = 'visible';
	}
	else
	{
	document.getElementById('myId').style.visibility = 'hidden';
	}
}
//--&gt;&lt;/script&gt;

"myId" is an ID of the div, I can put in it whatever I want (e.g. textbox, button) , it's like a panel for child controls, so once it's hidden, all childs will be hidden as well.

&lt;Select NAME="cboAct" onChange="T1(this.value);" style="width:200px;"&gt;

T1 is function and "this.value" gets the current selected item.

Thanks again

  • 0

When a <select> option is chosen then strictly the value property of the <select> isn't assigned (but might be to allow for "shorthand" script such as yours) but the selectedIndex property is. You then interrogate the options object in the <select> to get the value (or text) of the actual selected option.

That code looks like something a IE-centric IDE would spew out BTW...

&lt;script type="text/javascript"&gt;
function showPanel(sel){
	var el=document.getElementById('myId');
	el.style.visibility=(sel.options[sel.selectedIndex].value=='Item3')?'visible':'hidden';
}

&lt;select name="cboAct" style="width:200px;" onchange="showPanel(this);"&gt;
	&lt;option value="Item1"&gt;1&lt;/option&gt;
	&lt;option value="Item2"&gt;2&lt;/option&gt;
	&lt;option value="Item3"&gt;3&lt;/option&gt;
 &lt;/select&gt;

FWIW: <select />s aren't comboboxes. Comboboxes are extended <select />s that allow a text entry as well as selecting from a list (the dynamic Google search is a commo example). The Microsoft (and others) terminology for a <select> is "dropdown".

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I agree with open rights group that the age check companies should be regulated but action does need to be taken imo, they may be called irresponsible parents but the fact is that many don't know how to set up blocks. Why should kids suffer because their parents don't know something? I think the UK has always been a bit like this. We don't say healthcare is your responsibility, we tax everyone and make people register with the NHS. We also don't expect everyone to brush their teeth to maintain dental health, we just put fluoride in their water assuming people aren't brushing enough, because some probably aren't or aren't doing it properly. In general, this way of doing things works.
    • Well that's the weird thing, the UK really isn't a very religious country at all and the same politicians that are backing this (basically all of them) also support things like assisted dying which various religions spoke out against. I don't think this is coming from religion, of course religious groups will support it but I don't think they've started it.
    • No.  The only thing you'll be able to capture with that is via antenna (your local NBC, CBS, etc) or if you had a regular cable box you could capture ClearQAM channels (if they are still a thing...probably not though).  Everything else will have encryption which those capture cards aren't meant for.   So yeah...you'll need Verizon's DVR (sucks if you have to pay for it).
    • I've gotta say Microsoft has lost the plot a long, long, long time ago.
    • How is it be technically implemented, I mean if you wanted to include this let's say on this website, at what point do you interrupt the user flow and say yo! Show me your ID or get the hell out? Please go into extreme technical detail. Is it using a third-party, how much information does neowin receive from that third-party, at what point would that information be abused? We all know it would be abused. So hypothetically what would neowin receive from that third-party company?
  • Recent Achievements

    • One Month Later
      Falcon.ai earned a badge
      One Month Later
    • Week One Done
      Falcon.ai earned a badge
      Week One Done
    • Dedicated
      EYEREX earned a badge
      Dedicated
    • First Post
      Electronic Person earned a badge
      First Post
    • Week One Done
      CyberCeps666 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      628
    2. 2
      ATLien_0
      235
    3. 3
      Xenon
      164
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!