Javascript Confirm dialogue box help please

saviornt

New Member
Messages
4
Reaction score
0
Points
0
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 :(
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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...
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
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.
 

crisp

New Member
Messages
85
Reaction score
0
Points
0
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.
 
Top