Click to See Complete Forum and Search --> : Form validating: radio buttons, textbox


justpeachy
11-14-2003, 07:51 PM
Hello!

I am having a bit of trouble getting my forms to validate the input properly, and pop an alert if they do not validate.

I have this form:
<form name = "textfields">
<input type="text" name="quantity" size="10" onChange="compute_total()">
</form>

Here is the function that it calls, if that helps:

function compute_total() {

var ticketstring, ticketprice, subtotal, quantity;

ticketstring = document.locationform.location[document.locationform.location.selectedIndex].value;

ticketprice = ticketstring.substring(ticketstring.lastIndexOf("$"), ticketstring.length);

ticketprice = (ticketstring.match(/\d+/));

quantity = document.textfields.quantity.value;

subtotal = ticketprice * quantity;

document.textfields.subtotal.value = subtotal;

document.textfields.grandtotal.value = "";

}


What I'm trying to get it to do is check to see if the character entered is an integer; if not, it should pop an alert saying something to that effect.

The other thing I'm trying to validate is this set of radio buttons:

<form name = "delivery">
<input type="radio" name="delivery" onClick="delivery_charge()"> Will Call ($5) or
<br />
<input type="radio" name="delivery" onClick="delivery_charge()"> Overnight Delivery ($15)
</form>


They call this function:

var deliverycharge;

for (var i=0; i < 2; i++) {

//if (document.delivery.checked = false) {
// alert('Please select a method of delivery.');
// }

if (document.delivery[0].checked) {
deliverycharge= 5

document.textfields.deliverycharge.value = deliverycharge

document.textfields.grandtotal.value = "";

}

else if (document.delivery[1].checked) {
deliverycharge= 15

document.textfields.deliverycharge.value = deliverycharge

document.textfields.grandtotal.value = "";

}

}

}



This one just needs to make sure one of the two buttons is selected and pop an alert if there is not one selected.

The idea is that the calculation function will not run unless everything is complete and valid.

I've been looking around to find a simple way to validate- I have an idea of what I need to do but haven't been able to make it work yet. I could add checked="checked" to the properties of one of the radio buttons, but that doesn't do a whole lot for me... I don't really like it!

As always- any help is appreciated!
:)