Jump to content

Javascript function help


confusedman

Recommended Posts

hithis function is working alright but i want to display the output in the ex-vat textbox instead of a window prompt.HOW DO I DO IT?????here is the script fot yethanks in advanceconfused man

<script>-->    function Calculate() {     var cost=0;    if (document.ConsultantForm.Consultant[0].checked==true) //Document Object Model (DOM) address             cost = 1200;    else             cost = 1000;    if(document.ConsultantForm.phone.checked==true)             cost = cost + 45;    if(document.ConsultantForm.visit.checked==true)             cost = cost + 225;     DisplayPrice(cost);    } //End of Calculate – ALL local vars e.g. cost are distroyed   function DisplayPrice(y) {      alert("Consultant price: "+ y +" Euro");   } //End of DisplayPrice – parm var y is distroyed                     // -->   </script></head><body>   <form name=ConsultantForm>   <table border="1">      <tr>        <th>DESCRIPTION</th>  <th>COST</th>      </tr>            <tr>        <td><input type="radio" name="Consultant" value="A" checked>Senior Consultant</td>        <td>1200 Euro</td>      </tr>            <tr>        <td><input type="radio" name="Consultant" value="B">Junior Consultant</td>        <td>1000 Euro</td>      </tr>            <tr>        <td><input type="checkbox" name="phone">Immediate Phone Consultation</td>        <td>45 Euro</td>      </tr>            <tr>        <td><input type="checkbox" name="visit">Next day onsite visit</td>        <td>225 Euro</td>        </tr>                <tr>        <td>Price(ex VAT)</td> <td><input type="textbox" name="ex-vat" > </td>        </tr>                <tr>         <td>Total Price </td> <td><input type="textbox" name="total-vat"></td>        </tr>             </table>              </form>      <center>      <input type="button" onClick="Calculate()" value="Calculate Consultants Price" name="calc">      <input type="button" onClick="Clear()" value="Clear Current Selections" name="clear">      <input type="button" onClick="Database()" value="Submit to database" name="Submit">            </center>      </center>   </BODY></body></html>

Link to comment
Share on other sites

Sounds like it would make a good homework assignment to me.As far as writing out to the text field, follow the same idea as for ex-vat : add the id attribute to the text field and just use "mytextfield" instead of "ex-vat" when you use document.getElementByIdPassing values to functions is too basic, if you don't know how you need to studyhttp://www.w3schools.com/js/js_functions.asp

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...