Jump to content

replace radiobutton with a flip switch in a <form>


Recommended Posts

Hello everybody. I have a formal question aren't the following identical for js? I am trying to replace radiobuttons with what in normal html manifests as a dropdown menu and what in jqm is a flip switch, but it does not work that way. what could be the reason?

   <form name="BRAND" ><input type="radio" name="MODEL" value="1" checked /><input type="radio" name="MODEL"value="2" /></form>  

 <form name="BRAND" ><select data-role="slider" name="MODEL" ><option value="1">sedan</option><option value="2"> sportster</option></select> </form>

Link to comment
Share on other sites

what needed changing was the values from 1 vs 2 to on vs off. the proper piece of code is:

<form name="BRAND" ><select data-role="slider" name="MODEL" ><option value="off">sedan</option><option value="on"> sportster</option></select> </form>

consequently, the js needs to follow. from

 {for (ll=0;ll<document.BRAND.MODEL.length;ll++){if (document.BRAND.MODEL[ll].checked){MODEL=eval(ll+1)}}if (MODEL==1) {KIND="sedan"}if (MODEL==2) {KIND="sportster"} 

it should turn into

if (document.BRAND.MODEL.value=="off") {KIND="sedan"}if (document.BRAND.MODEL.value=="on") {KIND="sportster"}

here is the problems which follows:http://w3schools.invisionzone.com/index.php?showtopic=46567

Link to comment
Share on other sites

That could be more efficient.

<form name="brand">   <select data-role="slider" name="model" id="model">	  <option value="sedan">sedan</option>	  <option value="sportster">sportster</option>   </select></form>

and then

var kind = document.getElementById("model").value;

1. There's nothing wrong with using uppercase identifiers, but seasoned scripters use lowercase id's and camelCase variable names. 2. The dot syntax you were using technically works, but it's cumbersome if anything ever needs to be updated. I suspect you've been reading some old documentation.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...