This topic is locked

Update a field based on value of another field in Add/Edit

9/4/2010 2:54:10 AM
ASPRunnerPro General questions
W
waynes888 author

Is there a way to update a field based on the value of a another field multiplied by a value from another table. I don't mean a look-up wizard but this is what I need to do for booking:

  1. Add passengers and whether passenger is Adult or Child
  2. If Adult or Child selected the price needs to updated based on the price for that booking type, eg adult $50, child $30.
  3. The prices are stored in another table
  4. The price field must be just a numeric field and not a lookup value (foreign key) because the price cannot change once the booking is made. Therefore if it was based on a lookup of the booking type, it would change when the booking type price changed.
    I know I can do this once the record is saved through the custom scripts but I would rather have it updated when the Adult/Child option changes. I guess it would need an onchage event and a bit of ajax. Are there methods or example for this? What do I need to do to add my own Ajax for this?

Sergey Kornilov admin 9/7/2010

You can do this using Javascript API. This example can help you get started:

http://www.asprunner.com/forums/topic/14384-how-to-calculate-values-on-the-fly/
Since your logic requires a database call you'll need to implement a separate ASP page that retrieves data and make a call to this page from Javascript. Here is an example of how you can use AJAX call using jQuery:

http://api.jquery.com/jQuery.get/

W
waynes888 author 9/7/2010



You can do this using Javascript API. This example can help you get started:

http://www.asprunner.com/forums/topic/14384-how-to-calculate-values-on-the-fly/
Since your logic requires a database call you'll need to implement a separate ASP page that retrieves data and make a call to this page from Javascript. Here is an example of how you can use AJAX call using jQuery:

http://api.jquery.com/jQuery.get/


Thanks Sergey, I was playing around with jquery trying to get a dialog to open so that prices could be selected but couldn't get the dialog to open. Wondering if you could look at this code ad tell me what I am doing wrong:



Runner.util.ScriptLoader.addJS('include/js/jquery-ui-1.8.4.custom.min.js');

Runner.util.ScriptLoader.addJS('include/js/custom_js.js');


$('.testme').click(function() {
alert('working');

});

$('.ajaxLoad1').click(function() {



var url = this.href;

var dialog = $('<div style="display:hidden"></div>').appendTo('body');

// load remote content

dialog.load(

url,

{},

function (responseText, textStatus, XMLHttpRequest) {

dialog.dialog();

}

);

//prevent the browser to follow the link

return false;

});


The "testme" function works fine but the ajaxload function doesn't show the dialog - it does run the ajax query and I do get the response but doesn't just won't load the dialog. Not getting any javascript errors either so dialog must be recognised.
[edit] It appears that addJS is not adding the js - is that the correct way to add them?

Sergey Kornilov admin 9/8/2010

Just to be 100% sure I would use a suggested way to add Javascript files:

http://xlinesoft.com/asprunnerpro/docs/how_to_add_external_files.htm