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!

How to modify <select> value based on input from JS confirm window 1

Status
Not open for further replies.

Overspeed

Programmer
Jul 10, 2007
15
CA
Hello,

I have a <select> form field that uses the following JS:

function remindMe() {
if (document.getElementById('rec1pass').value == 'Night Season Pass') {
confirm("Did you know it is a better value to but an Almost Anytime Pass? Click OK to change your selection."); return false; }
}

with:

<select name="rec1pass" onChange="remindMe()" id="rec1pass">
<option value="Night Season Pass">Night Season Pass</option>
<option value="Day Season Pass">Day Season Pass</option>
<option value="Almost Anytime Pass">Almost Anytime Pass</option>
</select>

What i'm looking to do is remind my guests that one of our passes is a better value than another. As written, this works just fine ... but i'd like it so when a guest hits the OK button in the confirm window after selecting "Night Season Pass" the selection of rec1pass changes to "Almost Anytime Pass". This would be ideal rather then just using an alert window and forcing guests to have to manually change the selection. The cancel button would simply close the alert.

Can this be done? Thank you much.

Hugz

Jenny
 
It can be done like this:

Code:
function remindMe() {
   if (document.getElementById('rec1pass').value == 'Night Season Pass') {
      [!]if (confirm("Did you know it is a better value to but an Almost Anytime Pass? Click OK to change your selection.")) {
         document.getElementById("rec1pass").value = Almost Anytime Pass";
      }
      else {
         return false; 
      }[/!]
   }
}


[monkey][snake] <.
 
Just out of curiosity, do you think this could be done? You see the page in question actually has 8 select fields with ids "rec1pass" through "rec8pass". This allows for 8 family members to register. In a perfect world if Night Season Pass was chosen in any of the select fields the confirm window would be displayed offering ok or cancel as you wrote above. I need the same check to be place on the other 7 selects as well and I thought it might be redundant to create 8 functions .. IE ... remindMe1()remindMe2() remindMe3() .. etc. Also if the guest chose Cancel it would not keep asking them for other selects but would if Ok was selected in a previous select field.

Hope that made sense.

Hugz

Jenny
 
It can be done. Let's do one thing at a time though.
In your function call, pass the select box object.

Code:
<select name="rec1pass" onChange="remindMe([!]this[/!])" id="rec1pass">
<option value="Night Season Pass">Night Season Pass</option>
<option value="Day Season Pass">Day Season Pass</option>
<option value="Almost Anytime Pass">Almost Anytime Pass</option>
</select>

Code:
function remindMe([!]obj[/!]) {
if ([!]obj[/!].value == 'Night Season Pass') {
confirm("Did you know it is a better value to but an Almost Anytime Pass? Click OK to change your selection."); return false; }
}


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top