This code is the javascript for only one part of the site that I am creating for work. What I need this to do is accept input from the user about information that must be approved at a later time. the information is set in a form and needs to be approved later in the day by a supervisor. What I need is help with the code. it is not pulling information into the text area the way I need it to. This is the biggest thing that I need help with. please let me know where the issue/s are so that I may resolve them quickly.

<script type="text/javascript">

var x = document.getElementById(price).value;
var y = document.getElementById(disc).value;

function newDevice(){
var namebox = document.getElementById('cust').value;

var makebox = document.getElementById('make').value;

var mdnbox = document.getElementById('mdn').value;

var pricebox = document.getElementById('price').value;

var discbox = document.getElementById('disc').value;

var costbox = document.getElementById('cost').value;

var mirbox = document.getElementById('mir').value;

var insbox = document.getElementById('insurance').value;

var accbox = document.getElementById('acc').value;

var accpbox = document.getElementById('accp').value;

var ship = document.getElementById('ship').value;

var remarksbox = document.getElementById('Remarks').value;

remarksbox.value = "Customer: " + namebox.value +", requested " + makebox.value + ", for a new 2 year contract on MDN: " + mdnbox.value + " for the price of $" + pricebox.value + " and a discount of: $" + discbox.value + ". The total cost of the equipment is $" + costbox.value + " with an Mail in Rebate of: $" + mirbox.value + ". " + namebox.value +" has " + insbox.value + " Insureance. " + namebox.value + " has requested " + accbox.value + " for a total of $" + accpbox.value + ". The order is shipping via: " + shipbox.value + ". Full disclosures have been provided."

<body bgcolor="ivory">
<table border="1">


<td>New Device</td>


<!--//New Device Body-->

<td><form name="New">
<table><tr><td valign"right">

<tr><td>Name:</td><td><input id=cust onfocus="if(this.value=='Name'){this.value='';}" value="Name"></td></tr>

<tr><td>Make/Model:</td><td><input id="make" onfocus="if(this.value=='Device SKU'){this.value='';}" value="Device SKU"></td></tr>

<tr><td>Contract Term:</td><td>2 year contract</td></tr>

<tr><td>MDN:</td><td><input id=mdn onfocus="if(this.value=='MDN'){this.value='';}" value="MDN"></td></tr>

<tr><td>Price:</td><td><input id=price onfocus="if(this.value=='Price'){this.value='';}" value="Price"></td></tr>

<tr><td>Discount Amount:</td><td><input id=disc onfocus="if(this.value=='Discount'){this.value='';)" value="Discount"></td></tr>

<tr><td>Cost of Equipment:</td><td><script>document.write(x-y);</script></td></tr>

<tr><td>MIR Amount:</td><td><input id=mir onfocus="if(this.value='Mail in Rebate'){this.value='';}" value="Mail in Rebate"></td></tr>

<tr><td>Insurance:</td><td><select name="insurance" id=insurance><option value="TEC">TEC</option><option value="WPP">WPP</option><option value="EW">EW</
option><option vlue="Declined">Declined</option></select></td></tr>

<tr><td>Accessories:</td><td><input id=acc onfocus="if(this.value=='Accessories'){this.value='';}" value="Accessories"></td></tr>

<tr><td>Total Accessories price:</td><td><input id="accp" type="number" name="Acc Price" value="Price"></td></tr>

<tr><td>Shipped Via:</td><td><select name="shipping" id=ship><option value="FedEx">FedEx</option><option value="USPS">USPS</option></select></td></tr>

<tr><td colspan=2><button onclick=newDevice();>Click to copy New Device Remarks</button></td></tr>

<td><textarea id=Remarks onclick=javascript:this.focus();this.select(); rows=15 cols=30>Click Generate to show your remarks here!</textarea></td></tr>

Edited by pritaeas: Not a code snippet, restored to thread.

4 Years
Discussion Span
Last Post by theHop

you have a series of ids that do not have quotes... for example:

line 54:

<tr><td>Name:</td><td><input id=cust onfocus="if(this.value=='Name'){this.value='';}" value="Name"></td></tr>

id=cust --> id="cust"

You have tons of these.. fix your quotes, you will probably fix your issue.

Also, I recommend, for readability and so youre not inlining a ton of if checks...

function checkVal(element, string)
  if (element.value == string)
    element.value = "";

then the line above would be:
<tr><td>Name:</td><td><input id="cust" onfocus="checkVal(this, 'Name');" value="Name"></td></tr>


Lin 35 </head> does not have a starting tag. I suggest you to have comments onlines for you to debug your code easily.

Happy coding..


Do you have a test site we could look at and can you explain exactly what is not working with displaying the information?


line 29 has

var remarksbox = document.getElementById('Remarks').value;

but then after that you're doing

remarksbox.value = 

effectivly that translates as

remarksbox.value.value = 

change line 29 to:

var remarksbox = document.getElementById('Remarks');

in fact you've done the same with all of your elements. take the ".value" off the end of all lines from lines 7 - 29


you also have some inline events on elements that aren't surrounded by quotes. eg line 80
<tr><td colspan=2><button onclick=newDevice();>Click to copy New Device Remarks</button></td></tr>

this should be

 <tr><td colspan="2"><button onclick="newDevice();">Click to copy New Device Remarks</button></td></tr>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.