Jump to content

[SOLVED] Dont change value of drop down.. help :p


seventheyejosh

Recommended Posts

ok basically i need to have a drop down that when someone chooses an app type the 1st time, it just ajaxs and writes to the div underneath it... but if they change the value of the dropdown afterwards, i need a prompt to come up, if they hit ok to change type, i need to empty the div and rewrite to it. i have all this working fine. my problem is that if they hit cancel, i need the dropdown to revert to its previous value, or just not change at all.

 

a very simplified version of what i have now:

 

function update(){

 

var r=confirm("Changing the app. type will erase all entered data.");

 

if (r==true){  

                var ok=document.getElementById('that_select').value;

                        var url='path.to.folder.that.holds.'+ok+'.tpl';

sndReqList(url);

  }else{

return false;

  }

    }

 

and the html is simply:

 

 

blah blah onChange="return update();"

 

so if i do onclick it sends it right away, but if i do onchange the value is lost...

 

thanks to anyone who attempts to help with this mess :)

 

have a great day!

 

 

<script>
var lastSelection;
function update(){
  if(!lastSelection || confirm("Changing the app. type will erase all entered data.")){
    var ok=document.getElementById('that_select').value;
    var url='path.to.folder.that.holds.'+ok+'.tpl';
    sndReqList(url);
    lastSelection = document.getElementById('that_select').selectedIndex;
  }else{
    document.getElementById('that_select').selectedIndex = lastSelection;
  }
}
function sndReqList(url){
  alert(url);
}
</script>
<select id="that_select" onchange="update()">
  <option value="a">A</option>
  <option value="b">B</option>
  <option value="c">C</option>
</select>

 

this handles the "if it's the first change, just process it" case

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.