How to incorporate this? (javascript/php/html)

Associate
Joined
22 Aug 2011
Posts
240
Here's my code:

<form name="finish" method="post" action="#">
<input name="height" type="text" id="height" placeholder="enter height" />
<input name="width" type="text" id="width" placeholder="enter width" />
<input name="depth" type="text" id="depth" placeholder="enter depth" />
<input type="button" type="button" id="buttonenter" value="submit" />
</form>
<br />

<script type="text/javascript">
var price = 105;
if( price == 100 ){
document.write("Your product qualifies under the Normal wrapping service.");
}else if( price < 100 ){
document.write("Your product qualifies under the Small wrapping service.");
}else if(price > 100 ){
document.write("Your product qualifies under the Large wrapping service.");
}else{
document.write(unknown quantity");
}
</script>

Obviously by the form created, I want the users to input their height/width/depth and if when they press "submit" if then the following:

>100-200 - large
<10-60 - small
== 65-100 - normal

But i have no idea how to do it and I need to implement it for my third year project, anyone want to help a rookie out?
 
Associate
Joined
9 May 2005
Posts
121
Location
Yorkshire
The simplest thing to do would be to wrap your javascript in a function
Code:
<script type="text/javascript">
function checkPrice(){
var price = 105;
...
return;
}
</script>

and then on a onclick handler to your html button.

Code:
<input type="button" type="button" id="buttonenter" onclick="checkPrice()" value="submit" />

There are various other things to consider in terms of where you're outputting the message to but that's the basics :)

EDIT: I'm not sure how you're getting the price as in your example you've got price=105 however I'm presuming you'll want to get it from the form. However your form has 'height', 'width' and 'depth' fields - how are you getting from these dimensions to a price?
 
Last edited:
Back
Top Bottom