Closed Thread Icon

Preserved Topic: Submitting a form from a function Pages that link to <a href="https://ozoneasylum.com/backlink?for=18335" title="Pages that link to Preserved Topic: Submitting a form from a function" rel="nofollow" >Preserved Topic: Submitting a form from a function\

 
Author Thread
butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-12-2002 20:26

Sorry for the bad subject title.

I know this is probably a simple thing, but I just can't get it.

I have a form with a select box that I want to submit with the onChange handler (no submit button). This works fine except I want different things to happen based on the value of the option that's selected. If the extension of the option value is .pdf I want to pop it in a new window. That works fine so far.

If the extension of the selected option value is anything but .pdf I want the form to submit to the script specified in the form action.

I'm not sure how to make the form submit after it's gone to the function.

Here's my test page. It works as far as the popping the .pdf is concerned, I just can't figure out how to submit the damn thing!

Thanks guys (and gals)

-Butcher-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 03-12-2002 21:19

document.formName.submit();


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 03-12-2002 21:21

"Here's my test page."

Where? =)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-12-2002 21:36

Yeah as long as you have the onChange handler working then you just want something like this

function changehandler(formfield) {
if (formfield.value.indexOf('.pdf') {
// Insert window popping code here
} else {
document.formname.submit();
}

}

(this assumes you are passing the submit field ref like so (onChange="changehandler(this)")




.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-12-2002 21:38

LOL Sorry

Here it is:

code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ ME">
<script language="JavaScript">
<!--
// windowPop function courtesy of GurusNetwork.com

function windowPop(url,name) {
popupWin = window.open(url, name,'menubar,toolbar,location,directories,status,scrollbars,resizable,dependent,width=640,height=480')
}

function checkFileType(form) {
var selection = form.options[form.selectedIndex].value;
var extCheck = /[\w]*\.pdf$/
if (extCheck.test(selection)) {
var path = "/schedules/includes/" + selection;
var name = "pdf";
windowPop(path, name);
return false;
} else {
document.myNav.submit();
}
}
//-->
</script>
</HEAD>

<BODY>

<FORM NAME="myNav" ACTION="$PHP_SELF" METHOD="POST">
<SELECT NAME="nav" onChange="checkFileType(this);">
<OPTION value="">More - Tests -->
<OPTION value="test.content">Test 1</OPTION>
<OPTION value="test.pdf">Test 2</OPTION>
<OPTION value="test.gif">Test 3</OPTION>
</SELECT>
</FORM>

</BODY>
</HTML>



I tried that mr.maX and it didn't work, but I'll go try it again.

-Butcher-

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-12-2002 21:51

Thanks for the replies mr.maX, Slime, and Bitdamaged.

You were right (of course ) about the document.form.submit, but I had some other issues in my PHP code that I was missing.

It's all good now!!

Thanks again!

-Butcher-

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 03-13-2002 07:22

Is this a PHP issue that you're talking about, heh...

<FORM NAME="myNav" ACTION="$PHP_SELF" METHOD="POST">


butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-13-2002 12:52

No

It was the way my PHP code was building the options and their values, but thanks for checking back.

-Butcher-

« BackwardsOnwards »

Show Forum Drop Down Menu