c# - Why won't my JavaScript work in a ASP.net web form? -
i have no problems running code html page. now, in web form, converter nothing. trying migrate on web form page html use master page , theme.
<asp:content id="content1" contentplaceholderid="head" runat="server"> <script lang="javascript" type="text/javascript"> //convert logic function celsiusconvert() { document.converter.fahrenheit.value = (document.converter.celsius.value * 9 / 5) + 32 document.converter.kelvin.value = document.converter.celsius.value * 1 + 273.15 } function fahrenheitconvert() { document.converter.celsius.value = (document.converter.fahrenheit.value - 32) * 5 / 9 document.converter.kelvin.value = ((document.converter.fahrenheit.value - 32) * 5 / 9) + 273.15 } function kelvinconvert() { document.converter.celsius.value = document.converter.kelvin.value - 273.15 document.converter.fahrenheit.value = ((document.converter.kelvin.value - 273.15) * 9 / 5) + 32 } </script> </asp:content> <asp:content id="content2" contentplaceholderid="contentplaceholder1" runat="server"> <form name="converter"> <!--input fields--> celsius: <input type="text" name="celsius" onchange="celsiusconvert()"/><br /> fahrenheit: <input type="text" name="fahrenheit" onchange="fahrenheitconvert()"/><br /> kelvin: <input type="text" name="kelvin" onchange="kelvinconvert()"/><br /> <!--convert button--> <input type="button" value="convert!" /> </form> </asp:content>
webforms reserves <form>
tag can manage postbacks , take information in.
for start shouldn't using <form>
tag, can put them loose in page.
to @ them should give them id
's , use document.getelementbyid
access them (or use jquery).
as aside don't think method of accessing forms cross browser compatible either doesn't matter webforms removing anyway.
so this:
<asp:content id="content1" contentplaceholderid="head" runat="server"> <script lang="javascript" type="text/javascript"> //convert logic function celsiusconvert() { document.getelementbyid("fahrenheit").value = (document.getelementbyid("celsius").value * 9 / 5) + 32 document.getelementbyid("kelvin").value = document.getelementbyid("celsius").value * 1 + 273.15 } function fahrenheitconvert() { document.getelementbyid("celsius").value = (document.getelementbyid("fahrenheit").value - 32) * 5 / 9 document.getelementbyid("kelvin").value = ((document.getelementbyid("fahrenheit").value - 32) * 5 / 9) + 273.15 } function kelvinconvert() { document.getelementbyid("celsius").value = document.getelementbyid("kelvin").value - 273.15 document.getelementbyid("fahrenheit").value = ((document.getelementbyid("kelvin").value - 273.15) * 9 / 5) + 32 } </script> </asp:content> <asp:content id="content2" contentplaceholderid="contentplaceholder1" runat="server"> <div> <!--input fields--> celsius: <input type="text" name="celsius" id="celsius" onchange="celsiusconvert()"/><br /> fahrenheit: <input type="text" name="fahrenheit" id="fahrenheit" onchange="fahrenheitconvert()"/><br /> kelvin: <input type="text" name="kelvin" id="kelvin" onchange="kelvinconvert()"/><br /> <!--convert button--> <input type="button" value="convert!" /> </div> </asp:content>
i'm not saying great javascript code if want working can continue learning should trick.
Comments
Post a Comment