javascript form question
- Pout
- Born


- Joined: Dec 03, 2003
- Posts: 2
- Status: Offline
Here'z the script i have atm:
Now this gives me some problems:
When i filled in all the field correctly and hit the next button, it gives me the 'only digits in this field' alert. I don't know what causes that.
Second, when i click previous, all data inputed is supplied correctly, but let's say, when i click next again after 2 times previous it show all fields empty, if possible they should be filled in with the data (if there is any data that is)
Thirdly, i want to make it possible to override the autotab function when the user uses the Tab-key on the Keyboard so that adjustements can be made.
Hope u can help me on these matters
Thx in advance
Code: [ Select ]
<html>
<HEAD>
<script language="javascript">
<!--
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
function validateNum()
{
// digits letters only
if ( event.srcElement.value.search(/[^0-9]/) != -1 )
{
alert("only digits in this field");
this.focus();
return false;
}
return true;
}
}
var bDone = false;
function getValue(o)
{
o.value = document.inputform.result.value.substring(document.inputform.result.value.length - o.maxLength);
document.inputform.result.value = document.inputform.result.value.substring(0,document.inputform.result.value.length - o.maxLength);
}
function back()
{
if ( bDone ) return;
<!-- fill in the values in reverse order-->
getValue(document.inputform.field3);
getValue(document.inputform.field2);
getValue(document.inputform.field1);
}
function next()
{
if ( bDone ) return;
if (
!document.inputform.field1.onchange() ||
!document.inputform.field2.onchange() ||
!document.inputform.field3.onchange() ) return;
document.inputform.result.value += document.inputform.field1.value + document.inputform.field2.value + document.inputform.field3.value;
document.inputform.field1.value = '';
document.inputform.field2.value = '';
document.inputform.field3.value = '';
}
function done()
{
bDone = true;
document.getElementById('spResult').style.display = '';
}
-->
</script>
</HEAD>
<body>
<form name=inputform>
<table>
<tr>
<td>Field 1:</td>
<td><input name=field1 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.field2)"></td>
</tr>
<tr>
<td>Field 2:</td>
<td><input name=field2 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.field3)"></td>
</tr>
<tr>
<td>Field 3:</td>
<td><input name=field3 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.nextbutton)"></td>
</tr>
</table>
<input name="previousbutton" type="button" value="Previous" onClick="back();">
<input name="nextbutton" type="button" value="Next" onClick="next();">
<input name="donebutton" type="button" value="Done" onClick="done();">
<span id=spResult style="display:none;"><input type=text name=result></span>
</form>
</body>
</html>
<HEAD>
<script language="javascript">
<!--
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
function validateNum()
{
// digits letters only
if ( event.srcElement.value.search(/[^0-9]/) != -1 )
{
alert("only digits in this field");
this.focus();
return false;
}
return true;
}
}
var bDone = false;
function getValue(o)
{
o.value = document.inputform.result.value.substring(document.inputform.result.value.length - o.maxLength);
document.inputform.result.value = document.inputform.result.value.substring(0,document.inputform.result.value.length - o.maxLength);
}
function back()
{
if ( bDone ) return;
<!-- fill in the values in reverse order-->
getValue(document.inputform.field3);
getValue(document.inputform.field2);
getValue(document.inputform.field1);
}
function next()
{
if ( bDone ) return;
if (
!document.inputform.field1.onchange() ||
!document.inputform.field2.onchange() ||
!document.inputform.field3.onchange() ) return;
document.inputform.result.value += document.inputform.field1.value + document.inputform.field2.value + document.inputform.field3.value;
document.inputform.field1.value = '';
document.inputform.field2.value = '';
document.inputform.field3.value = '';
}
function done()
{
bDone = true;
document.getElementById('spResult').style.display = '';
}
-->
</script>
</HEAD>
<body>
<form name=inputform>
<table>
<tr>
<td>Field 1:</td>
<td><input name=field1 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.field2)"></td>
</tr>
<tr>
<td>Field 2:</td>
<td><input name=field2 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.field3)"></td>
</tr>
<tr>
<td>Field 3:</td>
<td><input name=field3 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.nextbutton)"></td>
</tr>
</table>
<input name="previousbutton" type="button" value="Previous" onClick="back();">
<input name="nextbutton" type="button" value="Next" onClick="next();">
<input name="donebutton" type="button" value="Done" onClick="done();">
<span id=spResult style="display:none;"><input type=text name=result></span>
</form>
</body>
</html>
- <html>
- <HEAD>
- <script language="javascript">
- <!--
- function autotab(original,destination){
- if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
- destination.focus()
- }
- function validateNum()
- {
- // digits letters only
- if ( event.srcElement.value.search(/[^0-9]/) != -1 )
- {
- alert("only digits in this field");
- this.focus();
- return false;
- }
- return true;
- }
- }
- var bDone = false;
- function getValue(o)
- {
- o.value = document.inputform.result.value.substring(document.inputform.result.value.length - o.maxLength);
- document.inputform.result.value = document.inputform.result.value.substring(0,document.inputform.result.value.length - o.maxLength);
- }
- function back()
- {
- if ( bDone ) return;
- <!-- fill in the values in reverse order-->
- getValue(document.inputform.field3);
- getValue(document.inputform.field2);
- getValue(document.inputform.field1);
- }
- function next()
- {
- if ( bDone ) return;
- if (
- !document.inputform.field1.onchange() ||
- !document.inputform.field2.onchange() ||
- !document.inputform.field3.onchange() ) return;
- document.inputform.result.value += document.inputform.field1.value + document.inputform.field2.value + document.inputform.field3.value;
- document.inputform.field1.value = '';
- document.inputform.field2.value = '';
- document.inputform.field3.value = '';
- }
- function done()
- {
- bDone = true;
- document.getElementById('spResult').style.display = '';
- }
- -->
- </script>
- </HEAD>
- <body>
- <form name=inputform>
- <table>
- <tr>
- <td>Field 1:</td>
- <td><input name=field1 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.field2)"></td>
- </tr>
- <tr>
- <td>Field 2:</td>
- <td><input name=field2 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.field3)"></td>
- </tr>
- <tr>
- <td>Field 3:</td>
- <td><input name=field3 type=text maxlength=1 onChange="java script:validateNum();" onKeyUp="autotab(this, document.inputform.nextbutton)"></td>
- </tr>
- </table>
- <input name="previousbutton" type="button" value="Previous" onClick="back();">
- <input name="nextbutton" type="button" value="Next" onClick="next();">
- <input name="donebutton" type="button" value="Done" onClick="done();">
- <span id=spResult style="display:none;"><input type=text name=result></span>
- </form>
- </body>
- </html>
Now this gives me some problems:
When i filled in all the field correctly and hit the next button, it gives me the 'only digits in this field' alert. I don't know what causes that.
Second, when i click previous, all data inputed is supplied correctly, but let's say, when i click next again after 2 times previous it show all fields empty, if possible they should be filled in with the data (if there is any data that is)
Thirdly, i want to make it possible to override the autotab function when the user uses the Tab-key on the Keyboard so that adjustements can be made.
Hope u can help me on these matters
Thx in advance
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
December 3rd, 2003, 3:13 am
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
The reason it's giving you the error when you click the next button has to do with the way the validateNum function is extracting the value to check it. When the Next button is clicked it is calling the onchange handler for the text boxes which in turn calls validateNum
It's using event.srcElement.value.search and it's the Next button that is generating the event in this case, so the value being checked is the value of the button which is just the string "Next" and that flunks the test.
I didn't have enough time to look at anyting else, but I'll try to look at it some more later. By the way you have an extra bracket in the validateNum function after return true and there shouldn't be any spaces in the word javascript inside the onchange handlers of the text boxes.
It's using event.srcElement.value.search and it's the Next button that is generating the event in this case, so the value being checked is the value of the button which is just the string "Next" and that flunks the test.
I didn't have enough time to look at anyting else, but I'll try to look at it some more later. By the way you have an extra bracket in the validateNum function after return true and there shouldn't be any spaces in the word javascript inside the onchange handlers of the text boxes.
Free Programming Resources
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 3 posts
- Users browsing this forum: No registered users and 188 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
