Forum Moderators: open
My script:
<SCRIPT LANGUAGE="JavaScript1.2">
// Form object
var f=document.form.begining;
//Count Parts var
var parts;
var parts_array=new array();
// Boolen to track if error found
var foundErr;
// Form element index number which the first error occured.
var focusOn;
function check_form() {
foundErr = false; focusOn = -1;
//Count Parts
parts = d.parts.value;
for(var i = 1; i <= parts; i++){
var a_part="part"+i;
parts_array[i] = d.a_part.value;
}
//test if part vals are the same if they are print error
var track = new Array();
for(var i = 1; i <= parts; i++){
if(parts_array[i] == "Track #"){
track[i] = true;
}
}
var name = new Array();
for(var i = 1; i <= parts; i++){
if(parts_array[i] == "Name"){
name[i] = true;
}
}
var artist = new Array();
for(var i = 1; i <= parts; i++){
if(parts_array[i] == "Artist"){
artist[i] = true;
}
}
var album = new Array();
for(var i = 1; i <= parts; i++){
if(parts_array[i] == "Album"){
album[i] = true;
}
}
var skip = new Array();
for(var i = 1; i <= parts; i++){
if(parts_array[i] == "Skip Value"){
skip[i] = true;
}
}
var chooseid3_arr = array(1=>"track", "name", "artist", "album", "skip");
for(var i = 1; i <= parts; i++){
for(var j = 1; j <= count(chooseid3_arr); j++){
if(parts_array[j]!= "Skip Value"){
if(parts_array[j] = chooseid3_arr[j]){
if(count(array.parts_array[j]) < 2){
foundErr = false;
}
else{
alert(chooseid3_arr[j] +"is set to more than one value");
foundErr = true
}
}
else{
foundErr = false;
}
}
}
//Has any error occured?
if (foundErr) {
//Yes. Focus on which the first occurred.
for(i = 1; i<=parts; i++){
pull = "part" + i.value;
f.pull.value = "Skip Value";
}
} else {
// No. Submit the form.
f.submit.disabled = true;
f.submit();
}
}
</SCRIPT>
Best of luck!
nothing happens when I run it. it just continues to the next page
Did you do this?
<form method="post" action="yourscript.cgi" onSubmit="return false;">
Or better yet as pointed out by RonPK: [webmasterworld.com]
<form onsubmit="return check_form()" action=[..]>
And make sure you alter your script so it returns false on error:
if (foundErr) {
//Yes. Focus on which the first occurred.
for(i = 1; i<=parts; i++){
pull = "part" + i.value;
f.pull.value = "Skip Value";
return false;
}
That being said, I must ask, are you making this task more difficult than it has to be? It indeed seems that alot of your repretive code may be easier managed by storing values in an array and looping through them.
At any rate, just FYI the modern script declaration is
<script type="text/javascript">