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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simulate vb like attaching vscrollbar to textbox

Status
Not open for further replies.

mrpro

Programmer
Oct 11, 2004
64
GB
is there any way of simulating vb like attaching vscrollbar to textbox using javascript

i wanted to do this for one of my datetime control which needs to increment or decrement time when you click on buttons..

here i am giving a bit more explanation what i am looking for

i have 4 text boxes

startdate starttime
enddate endtime

every time i click on increase or decrease button i should increase or decrease time..

any help is greatly appreciated.

 
i dont think that appearance can be given (CSS forum will give u answers), but for incrementing:
<input type="text" name="TheVal" readonly><input type="button" value="^" onclick="Increment()"><input type="button" value="V" onclick="Decrement()">

<script>
function Increment()
{
TheVl=parseInt(document.FormName.TheVal.value)
TheVl++
document.FormName.TheVal.value=TheVl
}
function Increment()
{
TheVl=parseInt(document.FormName.TheVal.value)
TheVl--
if(TheVl>=0)
{
document.FormName.TheVal.value=TheVl
}
}
</script>

Known is handfull, Unknown is worldfull
 
thanks vbkris for your response

i am not worrying about style

but the thing is we need to validate starttime along with startdate with the enddate and endtime

condition is enddate and endtime should always be greater than startdate and starttime.

i actually done this but i am looking for any simpler version..

Thanks

 
Here 's a code snippet for reference. It omits the date/time validation, e.g., second must be in the rang of 0 and 59, hence you can enter a second value of 90!

Code:
<style>
input {width: 33px; height: 20px;}
</style>

<script>
function checkIt() {
  var start=document.forms["fm1"];
  var stop=document.forms["fm2"];
  var startVal=parseInt(start.year.value+start.month.value+
                        start.date.value+start.hour.value+
                        start.min.value+start.sec.value);
  var stopVal=parseInt(stop.year.value+stop.month.value+
                       stop.date.value+stop.hour.value+
                       stop.min.value+stop.sec.value);
  if (stopVal>startVal) {
    alert("It's okay!");
  } else {
     alert("Invalid date/time!");
  }
}
</script>

<body>
<table border>
 <tr>
  <td></td>
  <td>date (yyyy-mm-dd)</td>
  <td>Time (hh:mm:ss)</td>
 </tr>
 <tr>
  <td>Start</td>
  <form name="fm1">
   <td>
    <input type="text" name="year" maxlength=4>-
    <input type="text" name="month" maxlength=2>-
    <input type="text" name="date" maxlength=2>
   </td>
   <td>
    <input type="text" name="hour" maxlength=2>:
    <input type="text" name="min" maxlength=2>:
    <input type="text" name="sec" maxlength=2>
   </td>
  </form>
 </tr>
 <tr>
  <td>Stop</td>
  <form name="fm2">
   <td>
    <input type="text" name="year" maxlength=4>-
    <input type="text" name="month" maxlength=2>-
    <input type="text" name="date" maxlength=2>
   </td>
   <td>
    <input type="text" name="hour" maxlength=2>:
    <input type="text" name="min" maxlength=2>:
    <input type="text" name="sec" maxlength=2>
   </td>
  </form>
 </tr>
</table>
<button onClick="checkIt();">Check It</button>
</body>

Hope it helps!
 
Thanks 13sio for taking time to post this

here are few things to work out i think you know
vscrollbar in vb will increment the time continuously when you hold the up arrow.

so
every time when you press up or down arrow button it should increase or decrease hour or miniutes and then it should validate the datetime and make sure that endtime is always greater than starttime..

any ideas..
 
i dont think that can be done (atleast not in a straight forward manner)...

Known is handfull, Unknown is worldfull
 
mrpro said:
here are few things to work out i think you know
vscrollbar in vb will increment the time continuously when you hold the up arrow.

Hope the following helps.
Code:
<html>

<script>
var flag=true;

function goUp() {
 if (flag) {
   document.fm.textbox.value++;
   setTimeout("goUp()",500);
 } else {
     flag=true;
 }
}

function goDn() {
 if (flag) {
   document.fm.textbox.value--;
   setTimeout("goDn()",500);
 } else {
     flag=true;
 }
}

document.onmouseup=new Function("flag=false;")
</script>

<body>
<form name="fm">
<input type="text" name="textbox" value=0>
</form>
<button onMouseDown="goUp()">Up</button>
<button onMouseDown="goDn()">Dn</button>

</body>
</html>
 
Thanks 13sio you gave me new thoughts to do this..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top