Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my if-else not working properly in javascript?
    primarykey
    data
    text
    <p>I have this form in which, when the order type selected is a market order the stop price and limit price should have value zero and should be readonly.</p> <p>when i select limit order it should make stop price 0 and read only.</p> <p>when i select stop order it should make limit price 0 and read only.</p> <p>i m trying to use simple if-else in js. What am i doing wrong?</p> <p>please try to avoid jquery. School project please. Thanks in advance...</p> <p>I have my code below.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;link rel="stylesheet" type="text/css" href="ETcss.css" /&gt; &lt;script src="jquery-1.10.2.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="header"&gt; &lt;h1 style="font-family: Cambria; color: #F0F0F0;" align="center"&gt;Welcome User&lt;/h1&gt; &lt;br&gt; &lt;/div&gt; &lt;div class="sidemenu"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="pmHome.html"&gt;Home&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="createOrder.html"&gt;Create Order&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="mainmenu"&gt; &lt;h1&gt;Create Equity Order&lt;/h1&gt; &lt;form action=""&gt; &lt;table&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Symbol :&lt;/td&gt; &lt;td&gt; &lt;input type="text" name="symbol" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Secutrity name :&lt;/td&gt; &lt;td&gt; &lt;input type="text" name="securityName" value="sapient" placeholder="sapient" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Side :&lt;/td&gt; &lt;td&gt; &lt;select&gt; &lt;option&gt;buy&lt;/option&gt; &lt;option&gt;sell&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Order Type :&lt;/td&gt; &lt;td&gt; &lt;select id="orderType"&gt; &lt;option value="market" selected&gt;market&lt;/option&gt; &lt;option value="limit"&gt;limit&lt;/option&gt; &lt;option value="stop"&gt;stop&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Order Qualifiers :&lt;/td&gt; &lt;td&gt; &lt;select&gt; &lt;option&gt;day order&lt;/option&gt; &lt;option&gt;gtc&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Trader :&lt;/td&gt; &lt;td&gt; &lt;select&gt; &lt;option&gt;trader1&lt;/option&gt; &lt;option&gt;trader2&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Account Type :&lt;/td&gt; &lt;td&gt; &lt;select&gt; &lt;option&gt;cash&lt;/option&gt; &lt;option&gt;margin&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Portfolio :&lt;/td&gt; &lt;td&gt; &lt;select&gt; &lt;option&gt;p1&lt;/option&gt; &lt;option&gt;p2&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Stop Price :&lt;/td&gt; &lt;td&gt; &lt;input type="text" id="stopprice" name="stopprice" readonly="readonly" onfocus="this.blur()" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Limit Price :&lt;/td&gt; &lt;td&gt; &lt;input type="text" id="limitprice" name="limitprice" readonly="readonly" onfocus="this.blur()" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"&gt; &lt;td&gt;Qty :&lt;/td&gt; &lt;td&gt; &lt;input type="text" name="qty" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;a href="pmHome.html"&gt; &lt;td colspan="2" align="center"&gt; &lt;input type="submit" onclick="display_alert()" value="Create Equity Order" /&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;script&gt; function updatePrice(el, priceLog, priceLog1, priceList) { var e = document.getElementById("orderType"); var pricevalue = e.options[e.selectedIndex].text; if (pricevalue.toLowerCase() == "market") { priceLog.value = priceList[el.getElementsByTagName('option')[el.selectedIndex].value .toLowerCase()]; priceLog1.value = priceList[el.getElementsByTagName('option')[el.selectedIndex].value .toLowerCase()]; } alert(pricevalue); else if (pricevalue.toLowerCase() == "limit") { document.getElementByName('limitprice').readOnly = false; priceLog.value = priceList[el.getElementsByTagName('option')[el.selectedIndex].value .toLowerCase()]; priceLog1.value = priceList[el.getElementsByTagName('option')[el.selectedIndex].value .toLowerCase()]; } else if (pricevalue.toLowerCase() == "stop") { document.getElementByName('stopprice').readOnly = false; priceLog.value = priceList[el.getElementsByTagName('option')[el.selectedIndex].value .toLowerCase()]; priceLog1.value = priceList[el.getElementsByTagName('option')[el.selectedIndex].value .toLowerCase()]; } } var stopPrices = { 'market' : 0, 'limit' : 1, 'stop' : 2, }; var limitPrices = { 'market' : 0, 'limit' : 1, 'stop' : 2, }; var select = document.getElementById('orderType'), hidden = document .getElementsByName('stopprice')[0]; hidden1 = document.getElementsByName('limitprice')[0]; select.addEventListener('change', function() { updatePrice(select, hidden, hidden1, stopPrices); }); &lt;/script&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload