Does anyone know a way i can achieve the following?
When a user enters 1 into the input box an alert popups but then i want the user to be able to either confirm the new value and it auto fills the input field with the minimum value or cancel and the field remains blank.
i have the following code so far:
function Form_Validator(theForm)
{
var err = false;
var field;
var msg = 'Please correct the following to continue...\n';
var alpha = /\w/;
var numeric = /[^0-9^\s]/;
var emailvalidator = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
var teststr = '';
if(theForm.prod_quantity.value == '1'){
msg += '\nThe minimum order amount is 2.';
if (!err){
field = theForm.prod_quantity;
err = true;
}
}
if (!err){
return true;
}
else{
alert(msg);
field.focus();
return false;
}
}
<b>Quantity:</b> <input type="text" class="prod_quantity" name="prod_quantity" />
<input type="submit" value="" class="add-basket-btn"/>
i have managed to make an alert box appear however i am not sure how to make it autofill in so that the value becomes 2 if they click ok. i hope this makes sense.
Use a simple
confirm()dialog instead ofalert()in a condition and set the desired value in your input box: