HTML/JavaScript ?

I asked this on an HTML forum with no luck. So I turn to you guys.

Basically a simple Javascript called by a form.

Look to the INPUT TYPE = BUTTON and INPUT TYPE = SUBMIT.

Input type BUTTON will fire the alert and load temp.htm.
Input type SUBMIT only fires the alert. temp.htm does not load.

Any ideas?

<HTML>
<HEAD>

function legalpre()
{
alert(document.frmSearch.QVALUE.value);
parent.TextFrame.location=“temp.htm”;
}
</SCRIPT>

</head>
<BODY>

<FORM name=“frmSearch” onSubmit=“legalpre()”>
<input name=“QVALUE” size=“7”>

<INPUT TYPE=“button” ONCLICK=“legalpre()”>
<INPUT TYPE=“submit” VALUE=“Search”>

</FORM>

</BODY>
</HTML>

Thanks…

You just need another function: say, legalpre2(), that fires the alert but does not redirect the user. Then change onSubmit to “legalpre2()”.

Hold on - is enipla saying what does happen, or what s/he wants to happen? Is it actually a quirk being described - in that both clicking BUTTON and SUBMIT should do the same thing, but they don’t?

OK, just tested it - it doesn’t work like it should. How odd.

Do you have to have the form submitting? If not, you could change the SUBMIT button to a BUTTON type and then use a form.submit() call from a second function, called by that button.

You got it. It seems to be a quirk. The BUTTON and SUBMIT should do the same thing, but they don’t. I want to use the SUBMIT so that the form is submited when the users hits an enter key.

The alert is just a test to see what the heck is happening. Just want to be sure the function gets called.

Of course it’s not working. You left out the action ONCLICK in the submit button definition :wally

Just teasing ya. I’ve done things like that too

Don’t know if I’ve been whooosed, but the SUBMIT button does not need an ONCLICK. It is calling the function, but not running the whole thing.

You still have to tell it which function to call. Let me go look up the specifics. Been a while since i did a form.

The function is defined by <FORM name=“frmSearch” onSubmit=“legalpre()”>

The SUBMIT button submits the form. onSubmit=“legalpre()” calls the function.

Thanks.

Nevermind…I really should read stuff more closely. I don’t see a problem with it, now that the memory is coming back. I’m still digging through my references to find a fix.

The end of an OnSubmit() call should submit the form itself.

I do notice one thing wrong: there is no <SCRIPT language=javascript> tag. Was that a typing error, or is this a copy-and-paste of the exact code?

Copy and paste, but I just didn’t grab enough of it.

The <script language=javascript> tag is one line above in the actuall code.

The crazy thing is, the function is getting called, but only the alert gets executed with the type=submit. The type=button executes the entire function.

That’s weird. I don’t get it either. Maybe just use the type=button deal and give up on the submit? Still it irritates me when I can’t solve a coding problem like this. :mad:

It works for me both in Mozilla and IE6

Here’s tframe.html



<HTML>
<HEAD><TITLE>Test Frame</TITLE>
</HEAD>
<FRAMESET cols="200,*">
  <frame name="main" src="test.html">
  <frame name="TextFrame">
</FRAMESET>
</HTML>


Here’s test.html (I added a <script… and a value=“button” to the type=Button input



<HTML>
<HEAD>
<script type="text/javascript">
function legalpre()
{
alert(document.frmSearch.QVALUE.value);
parent.TextFrame.location="temp.htm";
}
</SCRIPT>
</head>
<BODY>
<FORM name="frmSearch" onSubmit="legalpre()">
<input type="text" name="QVALUE" size="7">
<INPUT TYPE="button" value="Button" ONCLICK="legalpre()">
<INPUT TYPE="submit" VALUE="Search">
</FORM>
</BODY>
</HTML>


And temp.htm



<html>
<head><title>Temp.htm</title></head>
<body>
<h1>Temp.htm</ht>
</body>
</html>


Opening http://<my apache server>/tframe.html displays the two frames, clicking on either Button or Submit does the same thing. I played with having the function return false, to no effect.

Tried it with a different main frame page and it works.

My existing frame code is writen with javascript document.write statements -

I’m going to pull it out of the script and try straight html and see what happens.

Thanks, I’ll let you know.

AHA!

Change your tframe1.htm so that it updates the frame that the code exists in. That breaks it.

Like This - (move the scr=“test.html” into the TextFrame)

<HTML>
<HEAD><TITLE>Test Frame</TITLE>
</HEAD>
<FRAMESET cols=“200,*”>
<frame name=“main”>
<frame name=“TextFrame” src=“test.html”>
</FRAMESET>
</HTML>

Yeah, drives me nuts. Problem is, by using a type=submit, the form will be submitted if the user either presses the button OR just an enter key. That’s what I’m after.

Don’t want to force the button push.

Anyway, I explained in a couple posts up, the problem seems to be the function will not update the frame that calls it with a submit button. It will work with a button button.

It will work if I have the function call a different frame. Just not the one from the calling form.

Try modifying your Form tag thusly:

<FORM name=“formname” METHOD=“GET” ACTION=“http://page you want to update” onSubmit=“legalpre()”>

Try it with and without the italicized bit. I haven’t a server to check it out on at the moment.

grumbles about someone not paying her hosting bill

Hey, you might have something there.

I tried it earlier with the ACTION="http… bit. Did not work
Tried it with METHOD=“GET” got an error
Did not try it with both.

If I go with the ACTION route, I still need to pass the variable (QVALUE) from the form to the called script.

Can I put the QVALUE value in the arguments in the ACTION?

ACTION=“http://page.htm?VALUE=” + formname.QVALUE.value

I need to pass the value of QVALUE to page.htm formname.QVALUE.value is javascript. So that’s not right.

hmmm.

I’m at home now, but will work more on this in the morning.

Thanks