priyankadeven
Programmer
I have to create like a small calcultor/editor that contains 3 text boxes and a button.
When an ethernet address is written in the first text box "Hyphen" in this format eg: EE-8U-OO-90-II-PP and the button is clicked it should show the one text box - "Colon" filled with values like EE:8U:OO:90:II
P and the "Plain" filled with values like EE8UOO90IIPP.
I am able to take values from the first textbox and seperate the EE 8U 00 90 II PP and alert them in a text box.. But I dont know how to put the values in to the Colon or Plain text boxes...
I tried document.Form1.Col.value but that does not put the value in the text box.
Can someone please help me?
I have pasted the code I did so far.. but now I am stuck.. Appreciate if someone can give me a push to some point ahead from when I am ..
<body>
<script type="text/javascript">
function validate()
{
x=document.Form1;
var hyp = x.Hyphens.value;
var col = x.Colons.value;
var pla = x.Plain.value;
if (pla.length==0 && hyp.length==0 && col.length==0)
{
alert("Please enter values in any one"
}
if (pla.length!=0 && hyp.length!=0 && col.length==0)
{
alert("Please enter values in any one"
}
if (pla.length!=0 && hyp.length==0 && col.length!=0)
{
alert("Please enter values in any one"
}
if (pla.length==0 && hyp.length!=0 && col.length!=0)
{
alert("Please enter values in any one"
}
if (pla.length==0 && hyp.length!=0 && col.length==0)
{
//If there are values with hyphens entered
var pos=hyp.indexOf("-"
;
if (pos>=0)
{
alert("- found at position: "+pos)
var one=(hyp.substr(0,pos))
alert(one);
alert(hyp.substr(pos+1,hyp.length))
var rem = hyp.substr(pos+1,hyp.length);
var pos2 = rem.indexOf("-"
;
var two = rem.substr(0,pos2);
alert(two);
alert(rem.substr(pos2+1,rem.length))
var rem2 = (rem.substr(pos2+1,rem.length));
var pos3 = rem2.indexOf("-"
;
var three = rem2.substr(0,pos3);
alert(three);
alert(rem2.substr(pos3+1,rem2.length))
var rem3 = (rem2.substr(pos3+1,rem2.length))
var pos4 = rem3.indexOf("-"
;
var four = rem3.substr(0,pos4);
alert(four);
alert(rem3.substr(pos4+1,rem3.length))
var rem4 = (rem3.substr(pos4+1,rem3.length))
var pos5 = rem4.indexOf("-"
;
var five = rem4.substr(0,pos5);
alert(five);
alert(rem4.substr(pos5+1,rem4.length))
var six = (rem4.substr(pos5+1,rem4.length))
col = one+two+three+four+five+six;
alert(col); //This shows all in textbox
}
else
{
alert(" - not found!"
}
}
}
</script>
<center>
<p><b>Ethernet Calculator</b></p>
<table>
<tr>
<td align="left" valign="top">
<form name="Form1" method="POST" onSubmit="return validate();">
<font face="Times New Roman">
<input type="text" name="Hyphens" size="16"></font></p></td>
<td align="left" valign="top"><font face="Times New Roman">Hyphens</font></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Times New Roman"><input type="text" name="Colons" size="16"></font></td>
<td align="left" valign="top"><font face="Times New Roman">Colons</font></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Times New Roman"><input type="text" name="Plain" size="16"></font></td>
<td align="left" valign="top"><font face="Times New Roman">Plain</font></td>
</tr>
<tr>
<td align="left" valign="top">
<p align="center"><font face="Times New Roman">
<input type="submit" value="Calculate" name="calc"></font></p>
</form>
</p>
</td>
</tr>
</table>
</center>
Thank you
When an ethernet address is written in the first text box "Hyphen" in this format eg: EE-8U-OO-90-II-PP and the button is clicked it should show the one text box - "Colon" filled with values like EE:8U:OO:90:II
I am able to take values from the first textbox and seperate the EE 8U 00 90 II PP and alert them in a text box.. But I dont know how to put the values in to the Colon or Plain text boxes...
I tried document.Form1.Col.value but that does not put the value in the text box.
Can someone please help me?
I have pasted the code I did so far.. but now I am stuck.. Appreciate if someone can give me a push to some point ahead from when I am ..
<body>
<script type="text/javascript">
function validate()
{
x=document.Form1;
var hyp = x.Hyphens.value;
var col = x.Colons.value;
var pla = x.Plain.value;
if (pla.length==0 && hyp.length==0 && col.length==0)
{
alert("Please enter values in any one"
}
if (pla.length!=0 && hyp.length!=0 && col.length==0)
{
alert("Please enter values in any one"
}
if (pla.length!=0 && hyp.length==0 && col.length!=0)
{
alert("Please enter values in any one"
}
if (pla.length==0 && hyp.length!=0 && col.length!=0)
{
alert("Please enter values in any one"
}
if (pla.length==0 && hyp.length!=0 && col.length==0)
{
//If there are values with hyphens entered
var pos=hyp.indexOf("-"
if (pos>=0)
{
alert("- found at position: "+pos)
var one=(hyp.substr(0,pos))
alert(one);
alert(hyp.substr(pos+1,hyp.length))
var rem = hyp.substr(pos+1,hyp.length);
var pos2 = rem.indexOf("-"
var two = rem.substr(0,pos2);
alert(two);
alert(rem.substr(pos2+1,rem.length))
var rem2 = (rem.substr(pos2+1,rem.length));
var pos3 = rem2.indexOf("-"
var three = rem2.substr(0,pos3);
alert(three);
alert(rem2.substr(pos3+1,rem2.length))
var rem3 = (rem2.substr(pos3+1,rem2.length))
var pos4 = rem3.indexOf("-"
var four = rem3.substr(0,pos4);
alert(four);
alert(rem3.substr(pos4+1,rem3.length))
var rem4 = (rem3.substr(pos4+1,rem3.length))
var pos5 = rem4.indexOf("-"
var five = rem4.substr(0,pos5);
alert(five);
alert(rem4.substr(pos5+1,rem4.length))
var six = (rem4.substr(pos5+1,rem4.length))
col = one+two+three+four+five+six;
alert(col); //This shows all in textbox
}
else
{
alert(" - not found!"
}
}
}
</script>
<center>
<p><b>Ethernet Calculator</b></p>
<table>
<tr>
<td align="left" valign="top">
<form name="Form1" method="POST" onSubmit="return validate();">
<font face="Times New Roman">
<input type="text" name="Hyphens" size="16"></font></p></td>
<td align="left" valign="top"><font face="Times New Roman">Hyphens</font></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Times New Roman"><input type="text" name="Colons" size="16"></font></td>
<td align="left" valign="top"><font face="Times New Roman">Colons</font></td>
</tr>
<tr>
<td align="left" valign="top"><font face="Times New Roman"><input type="text" name="Plain" size="16"></font></td>
<td align="left" valign="top"><font face="Times New Roman">Plain</font></td>
</tr>
<tr>
<td align="left" valign="top">
<p align="center"><font face="Times New Roman">
<input type="submit" value="Calculate" name="calc"></font></p>
</form>
</p>
</td>
</tr>
</table>
</center>
Thank you