robbiez
09-26-2008, 04:21 PM
Hi
I am very, very new to Javascript and I am stuck.
I am trying to create a form that validates user input & then displays a price without leaving the page.
I have worked out all the validation part how do I make the form action display the result on the same page and not direct to a new page.
My form looks like this currently.
<form name="quick_price" id="quick_price" class="form" method="post">
<label for="length">Length(mm's)</label>
<input name="length" type="text" id="length" size="8" maxlength="5" />
<label for="width">Width(mm's)</label>
<input name="width" type="text" id="width" size="8" maxlength="5" />
<input type="submit" value="Check Price" onclick="return validate(this)" class="submit"/> </form>
and the validate javascript looks like this:
function validate(form) {
var length = quick_price.length.value;
var width = quick_price.width.value;
if(length == "") {
inlineMsg('length','You must enter a measurement.',3);
return false;
}
if(width == "") {
inlineMsg('width','You must enter a measurement.',3);
return false;
}
if(width < 100) {
inlineMsg('width','Enter a measurement over 100mm.',3);
return false;
}
if(width > 915) {
inlineMsg('width','Enter a measurement under 915mm.',3);
return false;
}
if(length < 100) {
inlineMsg('length','Enter a measurement over 100mm.',3);
return false;
}
if(length > 1220) {
inlineMsg('length','Enter a measurement under 1220mm.',3);
return false;
}
if (isNaN(length))
{inlineMsg('length','Numerics Only Please .',3);
return false;
}
if (isNaN(width))
{inlineMsg('width','Numerics Only Please.',3);
return false;
}
return true;
}
I can add a action="success.html" to the form tag which works fine but I want the action to be another javascript function, i.e. action="display_price ( )"
I can then create the display_price function to write the result in a specificed area on the same page.
A pointer in the right directions would be appreciated.
THanks
Rob
I am very, very new to Javascript and I am stuck.
I am trying to create a form that validates user input & then displays a price without leaving the page.
I have worked out all the validation part how do I make the form action display the result on the same page and not direct to a new page.
My form looks like this currently.
<form name="quick_price" id="quick_price" class="form" method="post">
<label for="length">Length(mm's)</label>
<input name="length" type="text" id="length" size="8" maxlength="5" />
<label for="width">Width(mm's)</label>
<input name="width" type="text" id="width" size="8" maxlength="5" />
<input type="submit" value="Check Price" onclick="return validate(this)" class="submit"/> </form>
and the validate javascript looks like this:
function validate(form) {
var length = quick_price.length.value;
var width = quick_price.width.value;
if(length == "") {
inlineMsg('length','You must enter a measurement.',3);
return false;
}
if(width == "") {
inlineMsg('width','You must enter a measurement.',3);
return false;
}
if(width < 100) {
inlineMsg('width','Enter a measurement over 100mm.',3);
return false;
}
if(width > 915) {
inlineMsg('width','Enter a measurement under 915mm.',3);
return false;
}
if(length < 100) {
inlineMsg('length','Enter a measurement over 100mm.',3);
return false;
}
if(length > 1220) {
inlineMsg('length','Enter a measurement under 1220mm.',3);
return false;
}
if (isNaN(length))
{inlineMsg('length','Numerics Only Please .',3);
return false;
}
if (isNaN(width))
{inlineMsg('width','Numerics Only Please.',3);
return false;
}
return true;
}
I can add a action="success.html" to the form tag which works fine but I want the action to be another javascript function, i.e. action="display_price ( )"
I can then create the display_price function to write the result in a specificed area on the same page.
A pointer in the right directions would be appreciated.
THanks
Rob