Go Back   SitePoint Forums > Forum Index > Program Your Site > JavaScript
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old May 23, 2004, 21:25   #1
etron
SitePoint Member
 
etron's Avatar
 
Join Date: Dec 2003
Location: kuala lumpur
Posts: 7
Javascript submit not working ...

Code:
	<script language = "javascript">
		function frmdisabletext(Form) {
			frm = Form;
			frm.changeuser.value = 'yes';
			frm.action = 'test.php';
			frm.submit();
		}
	</script>

	<?php
		$changeuser = $_POST["changeuser"];
		if ($changeuser == "yes") {
			$whichuser = $_POST["select_user"];

			switch ($whichuser) {
				case "teacher":
					$disabled1 = "disabled";
					break;

				case "teacher_under":
					$disabled2 = "disabled";
					break;

				case "moe":
					$disabled3 = "disabled";
					break;
			}
		}
	?>

		<table width="392" height="100%" border="0" cellpadding="0" cellspacing="0">

		<form name="formregister" method="post" action="processRegistration.php">
		<input type=hidden name="changeuser" value="">

        <tr><td><table width="390" height="98%" border="0" cellspacing="0" cellpadding="0" class="tableLine" align="center">

		<tr><td><br><br></td></tr>
		<TR><TD>
		  <table width="99%" height="98%" border="0">
                <tr>
                <td width="5%" class="text">&nbsp;</td>
                <td width="35%" class="text">User Type : <?=$changeuser?></td>
                <td width="54%"><select name="select_user" class="text" onChange="javascript:frmdisabletext(this.form);">
					<option value="" selected>- Select User Type -</option>
                    <option value="teacher">Teacher</option>
                    <option value="teacher_under">Teacher (under training)</option>
                    <option value="moe">MOE Officer</option>
                  </select></td>
                <td width="6%">&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td class="text">Name: <br></td>
                <td><input name="name" type="text" size="30" class="text"></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td class="text">State: </td>
                <td><select name="select_state" class="text">
                	<option>Perlis</option>
                	<option>Kedah</option>
                	<option>Pulau Pinang</option>
                	<option>Perak</option>
                	<option>Selangor</option>
                	<option>Melaka</option>
                	<option>N. Sembilan</option>
                	<option>Johor</option>
                	<option>Kelantan</option>
                	<option>Terengganu</option>
                	<option>Pahang</option>
                	<option>Sabah</option>
                	<option>Sarawak</option>
                	<option>Wilayah P. Kuala Lumpur</option>
                	<option>Wilayah P. Labuan</option>
                	</select></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td class="text">District/Town: </td>
                <td><input name="district" type="text" size="30" class="text" <?=$disabled1?><?=$disabled2?><?=$disabled3?>></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td class="text">School: </td>
                <td><input name="school" type="text" size="30" class="text" <?=$disabled1?><?=$disabled2?><?=$disabled3?>></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td class="text">Level: </td>
                <td><input name="level" type="text" size="5" class="text"></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>
				<table width="100%" border="0">
                    <tr>
                      <td width="82%" height="28">&nbsp;</td>
                      <input type="submit" class="submit" name="submit" value="Submit">
                      <input type="reset" class="submit" name="reset" value="Reset">
                    </tr>
                  </table></td>

                <td>&nbsp;</td>


            </table></td></tr>
          </table></td></tr>
		</form>
		</table>
I have this code ... the submit function wont work inside the javascript ... is the naming of the function name causing me the problem? or something else ...

It is not the page requested not found error ... it is the javascript ... cause there is an error icon in the status bar ... telling me that object doesn't support this method or property on line 6, char 4, code 0, which is : " frm.submit(); "

please help ... thanx ...
etron is offline   Reply With Quote
Old May 24, 2004, 07:16   #2
shoop
SitePoint Enthusiast
 
Join Date: Apr 2002
Posts: 75
Change onChange="java_script_:frmdisabletext(this.form);" to

onChange="frmdisabletext(this.form)"

and in your script change frm.submit() to frm.submit.click();
shoop is offline   Reply With Quote
Old May 24, 2004, 09:34   #3
adios
SitePoint Wizard
silver trophy
 
Join Date: May 2003
Posts: 1,844
Here's your problem:
Code:
<input type="submit" class="submit" name="submit"......
...which overwrites the Form.submit() method, making programmatic submission of the form impossible ("object doesn't support this....method"). Change that name!
Code:
function frmdisabletext(oSelect)
{
	if (oSelect.options[oSelect.selectedIndex].value)
	{
		var oForm = oSelect.form;
		oForm.elements.changeuser.value = 'yes';
		oForm.action = 'test.php';
		oForm.submit();
	}
}
............
............
<select name="select_user" class="text" onchange="frmdisabletext(this);">
The click() method should be avoided due to inconsistent support.
adios is offline   Reply With Quote
Old May 24, 2004, 19:26   #4
etron
SitePoint Member
 
etron's Avatar
 
Join Date: Dec 2003
Location: kuala lumpur
Posts: 7
thanx for pointing the problem to me ... it is now working as I want it to be ...

thank you adios and shoop for your replies ....
etron is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 23:01.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved