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

Debug help needed (noob)

Status
Not open for further replies.

SkiCheif

Technical User
Sep 8, 2004
30
US
I can't get this to run unless I comment out all of the information past the alert box (//var ...).


What am I doing wrong.

Really not that comfortable with this, but I usually can find and adapt a script or read a tutorial. I have some fairly complicated select case statements that I also need to execute.. can anyone recommend a good book for that?

Syntax?

------------------
<select name="cboHomeBoutScore" id="cboHomeBoutScore" onChange="UpdateFieldsForfiet()">
------------------

<script type="text/javascript">
function UpdateFieldsForfiet() {
alert ("Script entered");
}

var form = window.document.75_weigh_class_frm;
var HmWrestler = form.cboHomeWrestler;
var VsWrestler = form.cboVisitingWrestler;
var HmBoutScore = form.cboHomeBoutScore;
var VsBoutScore = form.cboHomeBoutScore;
var HmSeedPts = form.txtHomeSeed
var VsSeedPts = form.txtVisitingSeed
var HmMatchScore = form.txtHomeMatch
var VsMatchScore = form.txtVisitingMatch
var HmBoutOutcome = form.txtHomeBoutOutcome
var VsBoutOutcome = form.txtVisitingBoutOutcome
var time = prompt("Please say hello")
if HmBoutScore.value = "Forfiet"
{
form.HmBoutScore.value = 0
form.VsBoutScore.value = 6
form.HmSeedPts.value = 0
form.VsSeedPts.value = 7
form.HmMatchScore.value = 0
form.VsMatchScore.value = 6
form.HmBoutOutcome = "Loss by Forfiet"
form.VsBoutOutcome = "Win by Forfiet"
}
else
{
// do nothing
}
}
{
alert ("Made it to the bottom of the script");
}
</script>


------------------
 
Here is your problem:

Code:
function UpdateFieldsForfiet() {
alert ("Script entered");
}
This is all that exists in the UpdateFieldsForfiet() function. All of the other stuff is outside of the function, so the script tries to execute the vars before the page constructs itself, before the elements exist. Delete the "}" after the alert and you should be fine.
Also cut the
{
alert("Made...");
}
block, or delete the
}
{
before it.

--Chessbot

"DON'T PANIC
 
I trimmed the code to this:

----------------------
function UpdateFieldsForfiet() {
alert ("Script entered");


var form = window.document.75_weigh_class_frm;
var HmWrestler = form.cboHomeWrestler;
var VsWrestler = form.cboVisitingWrestler;
var HmBoutScore = form.cboHomeBoutScore;
var VsBoutScore = form.cboHomeBoutScore;
var HmSeedPts = form.txtHomeSeed;
var VsSeedPts = form.txtVisitingSeed;
var HmMatchScore = form.txtHomeMatch;
var VsMatchScore = form.txtVisitingMatch;
var HmBoutOutcome = form.txtHomeBoutOutcome;
var VsBoutOutcome = form.txtVisitingBoutOutcome;
//var time = prompt("Please say hello")
if HmBoutScore.value = "Forfiet"
{
alert ("Forfiet");
form.HmBoutScore.value = 0
form.VsBoutScore.value = 6
form.HmSeedPts.value = 0
form.VsSeedPts.value = 7
form.HmMatchScore.value = 0
form.VsMatchScore.value = 6
form.HmBoutOutcome = "Loss by Forfiet"
form.VsBoutOutcome = "Win by Forfiet"
}
}

</script>
----------------------


I realized after I posted that there were to many starts and stops when I went back to trim.
It still doesn't work this way. Do I need to have an ';' in the bold part of the statement?
 
if HmBoutScore.value = "Forfiet"

should be

if (HmBoutScore.value == "Forfiet")

Incidentally, isn't "forfiet(sic)" spelled "Forfeit"?


--Chessbot

"DON'T PANIC
 
Also, I don't believe that a form name can start with a number (75_weigh_class_frm). Try a75_weigh_class_frm, or something like that.

--Chessbot

"DON'T PANIC
 
Thanks for the help so far!

Changed what you noted, still not getting it to work.
I did some testing and the problem lies within the IF statement.

If I rem out the IF statement and put alert boxes to display the variables, they display--> [object]
instead of the values. Not sure, but seems that the variables aren't getting filled with the form elements.

I did go back and change the form name and updated the javascript code to reflect the change.

Here is the code again:

---------------------------------

<script type="text/javascript">

function UpdateFieldsForfiet() {
alert ("Script entered");


var form = window.document.match_information;
var HmWrestler = form.cboHomeWrestler;
var VsWrestler = form.cboVisitingWrestler;
var HmBoutScore = form.cboHomeBoutScore;
var VsBoutScore = form.cboHomeBoutScore;
var HmSeedPts = form.txtHomeSeed;
var VsSeedPts = form.txtVisitingSeed;
var HmMatchScore = form.txtHomeMatch;
var VsMatchScore = form.txtVisitingMatch;
var HmBoutOutcome = form.txtHomeBoutOutcome;
var VsBoutOutcome = form.txtVisitingBoutOutcome;
//var time = prompt("Please say hello")
if HmMatchScore == "Forfiet"
{
alert ("Home Wrestler Forfieted");
form.HmBoutScore.value = 0;
form.VsBoutScore.value = 6;
form.HmSeedPts.value = 0;
form.VsSeedPts.value = 7;
form.HmMatchScore.value = 0;
form.VsMatchScore.value = 6;
form.HmBoutOutcome = "Loss by Forfiet";
form.VsBoutOutcome = "Win by Forfiet";
}
Else
{
//do nothing
}
}

</script>




---------------------------------

 
Okay.. duh on my part
Found that the parens were missing in the logic of the IF statement. That solved my problem as far as getting into the function.

Still having the problem that the variables are displaying as [object]
 
[tt][object][/tt]will display because, say, HmWrestler is an object. If you change all instances of HmWrestler to HmWrestler.value, then you should be fine.

Here is revised code:
Code:
function UpdateFieldsForfiet() {
alert ("Script entered");


var the_form = window.document.match_information;
// just in case there is a naming collision

var HmWrestler = the_form.cboHomeWrestler;
var VsWrestler = the_form.cboVisitingWrestler;
var HmBoutScore = the_form.cboHomeBoutScore;
var VsBoutScore = the_form.cboHomeBoutScore;
var HmSeedPts = the_form.txtHomeSeed;
var VsSeedPts = the_form.txtVisitingSeed;
var HmMatchScore = the_form.txtHomeMatch;
var VsMatchScore = the_form.txtVisitingMatch;
var HmBoutOutcome = the_form.txtHomeBoutOutcome;
var VsBoutOutcome = the_form.txtVisitingBoutOutcome;

//test alert
alert("This should say [object]:\n" + HmWrestler);
alert("This should not:\n" + HmWrestler.value);

//var time = prompt("Please say hello")
       if (HmMatchScore.value == "Forfiet")
       {
            alert ("Home Wrestler Forfieted");
            form.HmBoutScore.value = 0;
            form.VsBoutScore.value = 6;
            form.HmSeedPts.value = 0;
            form.VsSeedPts.value = 7;
            form.HmMatchScore.value = 0;
            form.VsMatchScore.value = 6;
            form.HmBoutOutcome = "Loss by Forfiet";
            form.VsBoutOutcome = "Win by Forfiet";
      }
      Else
      {
              //do nothing
      }        
}

Try that.


--Chessbot

"DON'T PANIC
 
Okay, I was able to update my script to look like this:

--------------------------

<script type="text/javascript">

function UpdateFieldsForfiet() {

alert ("Script entered");

var entryForm = window.document.match_information;
var HmWrestler = entryForm.cboHomeWrestler;
var VsWrestler = entryForm.cboVisitingWrestler;
var HmBoutScore = entryForm.cboHomeBoutScore;
var VsBoutScore = entryForm.cboHomeBoutScore;
var HmSeedPts = entryForm.txtHomeSeed;
var VsSeedPts = entryForm.txtVisitingSeed;
var HmMatchScore = entryForm.txtHomeMatch;
var VsMatchScore = entryForm.txtVisitingMatch;
var HmBoutOutcome = entryForm.txtHomeBoutOutcome;
var VsBoutOutcome = entryForm.txtVisitingBoutOutcome;

//test alert
alert("This should say [object]:\n" + HmWrestler);
alert("This should not:\n" + HmWrestler.value);
//var time = prompt("Please say hello")
//alert ("b4 IF Statement");
if (HmMatchScore.value == "Forfiet")
{
alert ("Forfeit");
//entryForm.HmBoutScore.value = 0;
//entryForm.VsBoutScore.value = 6;
//entryForm.HmSeedPts.value = 0;
//entryForm.VsSeedPts.value = 7;
//entryForm.HmMatchScore.value = 0;
//entryForm.VsMatchScore.value = 6;
//entryForm.HmBoutOutcome = "Loss by Forfiet";
//entryForm.VsBoutOutcome = "Win by Forfiet";
}


}

</script>

--------------------------

I rem'd out all but the alerts. The [object] alert does display correctly and alert following does display the correct name, but no matter what I do nothing triggers the IF statement.

I had an ELSE in there and my ie browser gave me an error saying something like it wasn't supported? So I removed it entirely. Still, there doesn't seem a way to test the IF statement to see that the logic is being tested?

Again, I really appreciate the time that you have put into all of this, it's been a great learning experience for me.

 
When you run the script, what happens exactly?
i.e:
button clicked
"Script Entered" alerted
javascript error message:
Error on line 1: Evil text

you get the idea.

--Chessbot

"DON'T PANIC
 
I replaced the test string with the value from the drop down box. I think that the if statement is being entered, but no match is found:

The result in the message box is a hyphen? -

When I initially tested with your control (home wrestler name) the wrestlers name in the text box did appear.

In VBA you need to leave the control for the update to 'stick', is that the problem here?
 
Sorry for being so long getting back... my 13 year old races a car and I had to get it ready.

He started last after having electrical problems during the heat races and was running sixth when the friggin wheel literly ripped out of the center and ended the night.
Oh well, thats racin'!

I think the problem is referencing the the controls. I had some time this morinin to tinker and could not get any results.

Here is the current code:

______________________________________________

<script type="text/javascript">

function UpdateFieldsForfiet() {

alert ("Script entered");

var entryForm = window.document.match_information;
alert (entryForm)
var HmWrestler = entryForm.cboHomeWrestler;
alert (HmWrestler)
var VsWrestler = entryForm.cboVisitingWrestler;
var HmBoutScore = entryForm.cboHomeBoutScore;
var VsBoutScore = entryForm.cboHomeBoutScore;
var HmSeedPts = entryForm.txtHomeSeed;
var VsSeedPts = entryForm.txtVisitingSeed;
var HmMatchScore = entryForm.txtHomeMatch;
var VsMatchScore = entryForm.txtVisitingMatch;
var HmBoutOutcome = entryForm.txtHomeBoutOutcome;
var VsBoutOutcome = entryForm.txtVisitingBoutOutcome;


//test alert
alert("This should say [object]:\n" + HmWrestler);
alert("This should not:\n" + HmMatchScore.value);
//var time = prompt("Please say hello")
//alert ("b4 IF Statement");
if (HmMatchScore.value == "Forfiet")
{
alert ("Forfeit");
//entryForm.HmBoutScore.value = 0;
//entryForm.VsBoutScore.value = 6;
//entryForm.HmSeedPts.value = 0;
//entryForm.VsSeedPts.value = 7;
//entryForm.HmMatchScore.value = 0;
//entryForm.VsMatchScore.value = 6;
//entryForm.HmBoutOutcome = "Loss by Forfiet";
//entryForm.VsBoutOutcome = "Win by Forfiet";
}


}

</script>

______________________________________________

Never thought that something so simple in VBA would be so hard here.

Thanks again for your help.
Keith
 
Use this, see if it works:
Code:
<script type="text/javascript">

function UpdateFieldsForfiet() 
{
  var entryForm = window.document.match_information;
  var HmWrestler = entryForm.cboHomeWrestler;
  var VsWrestler = entryForm.cboVisitingWrestler;
  var HmBoutScore = entryForm.cboHomeBoutScore;
  var VsBoutScore = entryForm.cboHomeBoutScore;
  var HmSeedPts = entryForm.txtHomeSeed;
  var VsSeedPts = entryForm.txtVisitingSeed;
  var HmMatchScore = entryForm.txtHomeMatch;
  var VsMatchScore = entryForm.txtVisitingMatch;
  var HmBoutOutcome = entryForm.txtHomeBoutOutcome;
  var VsBoutOutcome = entryForm.txtVisitingBoutOutcome;
  if (HmMatchScore.value == "Forfeit")
  {
    HmBoutScore.value = 0;
    VsBoutScore.value = 6;
    HmSeedPts.value = 0;
    VsSeedPts.value = 7;
    HmMatchScore.value = 0;
    VsMatchScore.value = 6;
    HmBoutOutcome = "Loss by Forfeit";
    VsBoutOutcome = "Win by Forfeit";
  }
}
</script>

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
What exactly are you trying to do with this script? How are you calling it?

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top