Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get values in textbox dynamically

Status
Not open for further replies.

priyankadeven

Programmer
Nov 19, 2002
6
0
0
US
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:pP 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=&quot;text/javascript&quot;>

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(&quot;Please enter values in any one&quot;)
}

if (pla.length!=0 && hyp.length!=0 && col.length==0)
{
alert(&quot;Please enter values in any one&quot;)
}

if (pla.length!=0 && hyp.length==0 && col.length!=0)
{
alert(&quot;Please enter values in any one&quot;)
}

if (pla.length==0 && hyp.length!=0 && col.length!=0)
{
alert(&quot;Please enter values in any one&quot;)
}

if (pla.length==0 && hyp.length!=0 && col.length==0)
{
//If there are values with hyphens entered
var pos=hyp.indexOf(&quot;-&quot;);

if (pos>=0)
{
alert(&quot;- found at position: &quot;+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(&quot;-&quot;);
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(&quot;-&quot;);
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(&quot;-&quot;);
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(&quot;-&quot;);
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(&quot; - not found!&quot;)
}
}

}
</script>

<center>
<p><b>Ethernet Calculator</b></p>
<table>
<tr>
<td align=&quot;left&quot; valign=&quot;top&quot;>
<form name=&quot;Form1&quot; method=&quot;POST&quot; onSubmit=&quot;return validate();&quot;>
<font face=&quot;Times New Roman&quot;>
<input type=&quot;text&quot; name=&quot;Hyphens&quot; size=&quot;16&quot;></font></p></td>
<td align=&quot;left&quot; valign=&quot;top&quot;><font face=&quot;Times New Roman&quot;>Hyphens</font></td>
</tr>
<tr>
<td align=&quot;left&quot; valign=&quot;top&quot;><font face=&quot;Times New Roman&quot;><input type=&quot;text&quot; name=&quot;Colons&quot; size=&quot;16&quot;></font></td>
<td align=&quot;left&quot; valign=&quot;top&quot;><font face=&quot;Times New Roman&quot;>Colons</font></td>
</tr>
<tr>
<td align=&quot;left&quot; valign=&quot;top&quot;><font face=&quot;Times New Roman&quot;><input type=&quot;text&quot; name=&quot;Plain&quot; size=&quot;16&quot;></font></td>
<td align=&quot;left&quot; valign=&quot;top&quot;><font face=&quot;Times New Roman&quot;>Plain</font></td>
</tr>
<tr>
<td align=&quot;left&quot; valign=&quot;top&quot;>
<p align=&quot;center&quot;><font face=&quot;Times New Roman&quot;>
<input type=&quot;submit&quot; value=&quot;Calculate&quot; name=&quot;calc&quot;></font></p>
</form>
</p>
</td>
</tr>
</table>
</center>


Thank you
 
Like this:

Code:
<!DOCTYPE html 
     PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
     &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL]

<html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;[/URL] xml:lang=&quot;en&quot; lang=&quot;en&quot;>
  <head>
    <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;></meta>
    <title>JavaScript Sample</title>
    <script src=&quot;Sample.js&quot; type=&quot;text/javascript&quot;></script>
  </head>
  <body>
    <form name=&quot;MainForm&quot;>
      <p>Enter an IP address in one box, using the separation method next to the boxand click outside the box to populate the other two boxes.</p>
      <input type=&quot;text&quot; name=&quot;IPHyphenated&quot; onBlur=&quot;document.MainForm.IPColonized.value=document.MainForm.IPHyphenated.value.replace(/-/g,':');document.MainForm.IPCrammed.value=document.MainForm.IPHyphenated.value.replace(/-/g,'');return true;&quot;></input> (Use Hyphens to separate: xx-xx-xx-xx)<br />
      <input type=&quot;text&quot; name=&quot;IPColonized&quot; onBlur=&quot;document.MainForm.IPHyphenated.value=document.MainForm.IPColonized.value.replace(/:/g,'-');document.MainForm.IPCrammed.value=document.MainForm.IPColonized.value.replace(/:/g,'');return true;&quot;></input> (Use Colons to separate: xx:xx:xx:xx)<br />
      <input type=&quot;text&quot; name=&quot;IPCrammed&quot; disabled=&quot;disabled&quot;></input> (Can't enter into this one, sorry.)<br />
    </form>
  </body>
</html>

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top