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!

 

 

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.