Need help with a .blur() function on a <select> default condition

Sonny Forelli

Well-known member
May 8, 2008
2,330
89
48
Liberty City
Can anyone point me in the right direction with this?

I have the following occuring:

<select> with option values to test what something is worth to a user - I'm varying the form processing based on the selection.

Everything functions fine, EXCEPT that in the <option value> code I'm using selected=selected on the $25.00 price (case)

What occurs is that everything functions great BUT if the user leaves the defaulted $25 and clicks the form submit button nothing happens, since the blur hasn't happened.

Can anyone point me in the direction of what I'd need to do to basically set the value onload for the selected amount to prevent this?

Here's the (hacky, yes for sure) code.



HTML:
   //vary upsell based on selected price//
   
   
   
                jQuery("#selectedprice").blur(function(){
                
                        
                        var choice = $("#selectedprice option:selected").val();    
                        
                        switch(choice)
                        {
                            case "1.00": $("#submitimage").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
    $.post("noupsell.php",        // PERFORM AJAX POST
      $("#priceselect").serialize(),      // WITH SERIALIZED DATA OF MYFORM
      function(data){                // DATA NEXT SENT TO COLORBOX
        $.fn.colorbox({
          html:   data,
          open:   true,
          iframe: false,            // NO FRAME, JUST DIV CONTAINER?
          width:  "750px",
          height: "650px",
          opacity: .50,
          onClosed:function(){ location.reload(true); } 

        });
      },
      "html");
  });
  ;
                                       
                                break;
                                
                            case "5.00": $("#submitimage").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
    $.post("noupsell.php",        // PERFORM AJAX POST
      $("#priceselect").serialize(),      // WITH SERIALIZED DATA OF MYFORM
      function(data){                // DATA NEXT SENT TO COLORBOX
        $.fn.colorbox({
          html:   data,
          open:   true,
          iframe: false,            // NO FRAME, JUST DIV CONTAINER?
          width:  "750px",
          height: "650px",
          opacity: .50,
          onClosed:function(){ location.reload(true); } 

        });
      },
      "html");
  });
  ; 
                                break;
                                
                                
                            case "10.00": $("#submitimage").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
    $.post("upsell.php",        // PERFORM AJAX POST
      $("#priceselect").serialize(),      // WITH SERIALIZED DATA OF MYFORM
      function(data){                // DATA NEXT SENT TO COLORBOX
        $.fn.colorbox({
          html:   data,
          open:   true,
          iframe: false,            // NO FRAME, JUST DIV CONTAINER?
          width:  "750px",
          height: "650px",
          opacity: .50,
          onClosed:function(){ location.reload(true); } 

        });
      },
      "html");
  });
  ; 
                                break;
                                
                            case "25.00": $("#submitimage").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
    $.post("upsell.php",        // PERFORM AJAX POST
      $("#priceselect").serialize(),      // WITH SERIALIZED DATA OF MYFORM
      function(data){                // DATA NEXT SENT TO COLORBOX
        $.fn.colorbox({
          html:   data,
          open:   true,
          iframe: false,            // NO FRAME, JUST DIV CONTAINER?
          width:  "750px",
          height: "650px",
          opacity: .50,
          onClosed:function(){ location.reload(true); } 

        });
      },
      "html");
  });
  ; 
                                break;
                                
                                
                            case "50.00": $("#submitimage").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
    $.post("upsell.php",        // PERFORM AJAX POST
      $("#priceselect").serialize(),      // WITH SERIALIZED DATA OF MYFORM
      function(data){                // DATA NEXT SENT TO COLORBOX
        $.fn.colorbox({
          html:   data,
          open:   true,
          iframe: false,            // NO FRAME, JUST DIV CONTAINER?
          width:  "750px",
          height: "650px",
          opacity: .50,
          onClosed:function(){ location.reload(true); } 

        });
      },
      "html");
  });
  ; 
                                break;
                                
                            case "75.00": $("#submitimage").click(function () { // ATTACH CLICK EVENT TO MYBUTTON
    $.post("upsell.php",        // PERFORM AJAX POST
      $("#priceselect").serialize(),      // WITH SERIALIZED DATA OF MYFORM
      function(data){                // DATA NEXT SENT TO COLORBOX
        $.fn.colorbox({
          html:   data,
          open:   true,
          iframe: false,            // NO FRAME, JUST DIV CONTAINER?
          width:  "750px",
          height: "650px",
          opacity: .50,
          onClosed:function(){ location.reload(true); } 

        });
      },
      "html");
  });
  ; 
                                break;
                        }
                        
                        
            
            
                });
 


Thanks - for some reason this did work but was then triggering the post firing both upsell.php and noupsell.php form actions.

Coupled with some other issues I decided to scrape the jquery and just use php and build some simple decisioning logic to route accordingly and then fire the lightbox where I want it off the onload.

This works and seems to work better cross browser especially w/ how IE/Firefox process .change() differently.

Last thing I want is a bombed test b/c the 60% of people on some odd broswer config that middle america loves couldn't order the product they wanted.

Thank you though, really appreciate it!