Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Box Help 1

Status
Not open for further replies.

fmrock

Programmer
Sep 5, 2006
510
US
I am working on creating an tiff viewer with a 3rd part plugin. There example to resize the images had radio buttoms that call javascript functions.

I am trying to change this

Code:
<input name="swnormal" type="radio" onClick="javascript:OnSWNormal()">Show normal<br> 
<input type="radio" name="swdpi" onClick="javascript:OnSWdpi()">Scale to DPI<br> 
<input type="radio" name="swfitwidth" onClick="javascript:OnSWfitwidth()">Fit to width<br> 
<input type="radio" name="swfitheight" onClick="javascript:OnSWfitheight()">Fit to height<br> 
<input type="radio" name="swfitwindow" onClick="javascript:OnSWfitwindow()">Fit to height

to something more like this.

Code:
<select>
<option value="swnormal"  onChange="javascript:OnSWNormal()">Show normal</option>
<option value="swdpi" onChange="javascript:OnSWdpi()">Scale to DPI</option>
<option value="swfitwidth" onChange="javascript:OnSWfitwidth()">Fit to width</option>
<option value="swfitheight" onChange="javascript:OnSWfitheight()">Fit to height</option>
<option value="swfitwindow" onChange="javascript:OnSWfitwindow()">Fit to height</option>
</select>
I dont think the onchange can be in the option tag, and must be in the select tag. Any help would be great.

 
Hi

First of all, remove the pseudo-protocol from the event handler calls :
Code:
<input name="swnormal" type="radio" onClick="[s][red]javascript:[/red][/s]OnSWNormal()">

[gray]// ... and so on ...[/gray]

Feherke.
 
I would like the options in a drop down list instead of the radio buttons, The radio buttons is the example given by the 3rd party.

This didnt work.

Code:
                <select name="Scale" id="Scale">
                <option value="swnormal"  onChange="OnSWNormal()">Show normal</option>
                <option value="swdpi" onChange="OnSWdpi()">Scale to DPI</option>
                <option value="swfitwidth" onChange="OnSWfitwidth()">Fit to width</option>
                <option value="swfitheight" onChange="OnSWfitheight()">Fit to height</option>
                <option value="swfitwindow" onChange="OnSWfitwindow()">Fit to height</option>
                </select>
 
Hi

Code:
<select name="Scale" id="Scale" onChange="OnScale()">
<option value="swnormal">Show normal</option>
<option value="swdpi">Scale to DPI</option>
<option value="swfitwidth">Fit to width</option>
<option value="swfitheight">Fit to height</option>
<option value="swfitwindow">Fit to height</option>
</select>
They add a [tt]switch[/tt] ot more [tt]if[/tt] statements into the OnScale() function to treat the different situations.

Feherke.
 
Thanks feherke,

Can you give me an example of the if statements to use for this.

Code:
	function OnScale()
	{

	}

Thanks for all your help.
 
Hi

Well, practically the simplest is to pass a reference to the function :
HTML:
<select name="Scale" id="Scale" onChange="OnScale([red]this[/red])">
</select>
JavaScript:
function OnScale(what)
{
  switch(what.selectedIndex) {
    case 0:
      alert('You selected "Show normal".');
    break;
    case 1:
      alert('You selected "Scale to DPI".');
    break;

[gray]// ... and so on ...[/gray]
    
  }
}

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top