+ Reply to Thread
Results 1 to 4 of 4

Thread: Javascript Confirm dialogue box help please

  1. #1
    saviornt is offline x10Hosting Member saviornt is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    4

    Javascript Confirm dialogue box help please

    Quick question on a confirm dialogue box function I am currently working on.

    I have a form with a few text fields. These are:

    Textfield 1: ID = "item"
    Textfield 2: ID = "price"
    Textfield 3: ID = "quantity"
    Textfield 4: ID = "type" (Buy or Sell)

    On the submit button, I have an onClick = 'calcFields();'

    This calls up a function:

    <script type="text/javascript">
    function calcFields() {
    confirm("Are you sure you want to place this order?");
    }
    </script>

    Ok, so this actually works. The confirm box shows up, no problem. However, when I try to add stuff into the confirm box:

    <script type="text/javascript">
    function calcFields() {
    var val1 = getDocumentById("price").value;
    var val2 = getDocumentById("quantity).value;
    var val3 = val1 * val2;
    var valItem = getDocumentById("item").value;
    var valType = getDocumentById("type").value;
    confirm('Are you sure you want to ' + valType +
    'units of ' + valItem + ' for $' + val3 + ' ?');
    }
    </script>

    It breaks down completely. No confirm box, and the form submits itself. Any thoughts? Couldn't find a tutorial online to help solve this

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Javascript Confirm dialogue box help please

    If you're using Firefox, I would highly recommend getting 2 extensions if you don't already have them. Web Developer toolbar and Firebug. They are indispensible extensions that can properly debug javascript. Web deveoper can show you if there's any errors in the javascript and firebug, you can set breakpoints and more.

    I am not that experienced with JavaScript, but I don't see any problems in that code...

  3. #3
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: Javascript Confirm dialogue box help please

    You're missing a quote on this line, it can't be good:
    var val2 = getDocumentById("quantity).value;
    As for the rest, my poor JS experience does not report anything else.

  4. #4
    crisp is offline x10Hosting Member crisp is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    85

    Re: Javascript Confirm dialogue box help please

    Try using document.getElementById()

    instead of

    getDocumentByID()

    since it's element id's you're trying to get.

    Also, grab a copy of Firefox if you're not already using it, make sure you install the web developer toolbar too, then pop on over to Firefox add-ons and install Firebug which will help you no end with debugging js calls.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 08-17-2008, 01:46 AM
  2. Making a site JavaScript dependent - pros/cons?
    By Tarzan in forum Programming Help
    Replies: 8
    Last Post: 07-11-2008, 10:08 AM
  3. drop down menus with JavaScript disabled?
    By sifaka in forum Free Hosting
    Replies: 1
    Last Post: 05-15-2008, 10:46 AM
  4. javascript and external javascript files problem
    By delon in forum Programming Help
    Replies: 6
    Last Post: 04-27-2008, 12:41 AM
  5. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers